-1

I am trying to simulate the bouncing ball effect on unity for my isometric game. I got a code to make that and it works fine from this link: https://physics.stackexchange.com/questions/256468/model-formula-for-bouncing-ball#:~:text=The%20coefficient%20of%20restitution%20is,ball%20it%20is%20around%200.75.

I want to convert the resulting movement, namely the (h) to iso. I end up with this two-equation

        // Walk from current postion in ISO line
          transform.position = new Vector2(transform.position.x + oneCellSize, 
              transform.position.y + (oneCellSize * IsoRatio));

        // Perfect bouncing effect on ISO line but in wrong position
          transform.position = new Vector2(transform.position.x + 0.02f, 
            (transform.position.x + oneCellSize) * IsoRatio +  BallHightOnTime );

But I failed to merge them together as the second one is using the x position. When I tried to change to y, it just moves in a crazy way.

Ali Albahrani
  • 105
  • 1
  • 1
  • 7
  • Sorry I cant understand "this two-equation", the verticle position in a projectile motion is `v0*t - g*t*t/2`. The argument t is the time since the motion starts. – shingo Oct 15 '20 at 05:00
  • Those formals are used in the code link provided and the result of them is given in ( BallHightOnTime ) variable used in the 2nd equation. – Ali Albahrani Oct 15 '20 at 11:06
  • If you are sure BallHightOnTime is calcuted correctly, maybe the problem is the brackets before BallHightOnTime, I think it should be `transform.position.y + (oneCellSize * IsoRatio) + BallHightOnTime` – shingo Oct 15 '20 at 11:39
  • Where is the 3rd dimension? You are moving only in a 2D plane, you need to use the function that transforms a 3D position to the 2D ISO coord. Without knowing the projection it would look something like `iso.x = (b.x + b.y) * IsoRatio; iso.y = (b.x + b.y) * IsoRatio - b.z * IsoZRatio; ` Where `b` is the balls 3D position and `iso` the 2D projected pos. Note that most Iso projections will have a different ratio for the z axis, and if you are using (for example) a 2 by 1 iso grid the x and y axis would each have their own ratios (scale is the preferred term rather than ratio) – Blindman67 Oct 15 '20 at 12:26
  • Will Shingo, I have tried to do that, but for some reason, the ball starts to fly very high with crazy y reading! However, when using the transform.postion.x, it works almost write, but it was moving in the wrong direction, and I don't want it to work with the x coordinate – Ali Albahrani Oct 18 '20 at 00:51
  • Blindman67 I don't use the z-axis as I am working with the 2D project in unity, so Z has nothing to do with the moving aspect. For your provided formula, I did not understand are they for movement or for converting the iso coordinate to the world coordinate. BTW, I have a gird object that I use to do that, but I can't see how that will help in this situation? – Ali Albahrani Oct 18 '20 at 00:56

1 Answers1

0

Using some of your help guyz, I have come up with a solution to my problem by creating a separate vector that moves according to the ISO line and then assigns it to the ball position after adding the calculated hight.

Thank you guys for your help.

Ali Albahrani
  • 105
  • 1
  • 1
  • 7