Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualtom_mai78101

Posted 10 October 2012 - 11:37 AM

It may seem simple enough, but I realized how tough it is to get it right.

Here's my basic logic:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){for (int i = 0; i < 2; i++){ speed[i] += acceleration[i]; position[i] += speed[i]; speed[i] *= 0.1f;}}//Some codes were called to render everything.[/source]
You may noticed that I multiply 0.1 to the speed values. The reason is that, due to game logic requirements, the acceleration values can easily speed up the speed values within a fraction of a second. I would like it so that the objects can move just as fast when it's accelerating, but takes a while to slow down when its deaccelerating.

I did thought about doing this:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){for (int i = 0; i < 2; i++){ tempValues[i] += acceleration[i]; speed[i] += tempValues[i]; position[i] += speed[i]; speed[i] *= 0.1f;}}//Some codes were called to render everything.[/source]

I made the acceleration a cubic power, and if I were to convert the values down to position, it will create a rippling effect of decreasing power and lengthening the time it takes to stop itself from increasing when the ball is slowing down. I could make it like this, if I want:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){for (int i = 0; i < 2; i++){ tempValuesN[i] += acceleration[i]; tempValuesN1[i] += tempValuesN[i]; //... //... tempValues3[i] += tempValues4[i]; tempValues2[i] += tempValues3[i]; tempValues1[i] += tempValues2[i]; tempValues[i] += tempValues1[i]; speed[i] += tempValues[i]; position[i] += speed[i]; speed[i] *= 0.1f;}}//Some codes were called to render everything.[/source]

But that would be very unrealistic and very unreasonable. Are there any other ways to make the deacceleration work nicely, behaving like the ball in the game Teeter for Android?

#1tom_mai78101

Posted 10 October 2012 - 11:37 AM

It may seem simple enough, but I realized how tough it is to get it right.

Here's my basic logic:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){ for (int i = 0; i < 2; i++){ speed[i] += acceleration[i]; position[i] += speed[i]; speed[i] *= 0.1f; }}//Some codes were called to render everything.[/source]
You may noticed that I multiply 0.1 to the speed values. The reason is that, due to game logic requirements, the acceleration values can easily speed up the speed values within a fraction of a second. I would like it so that the objects can move just as fast when it's accelerating, but takes a while to slow down when its deaccelerating.

I did thought about doing this:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){ for (int i = 0; i < 2; i++){ tempValues[i] += acceleration[i]; speed[i] += tempValues[i]; position[i] += speed[i]; speed[i] *= 0.1f; }}//Some codes were called to render everything.[/source]

I made the acceleration a cubic power, and if I were to convert the values down to position, it will create a rippling effect of decreasing power and lengthening the time it takes to stop itself from increasing when the ball is slowing down. I could make it like this, if I want:

[source lang="java"]//Some codes were called to update acceleration values.public void accelerate(){ for (int i = 0; i < 2; i++){ tempValues5[i] += acceleration[i]; tempValuesN1[i] += tempValuesN[i]; //... //... tempValues3[i] += tempValues4[i]; tempValues2[i] += tempValues3[i]; tempValues1[i] += tempValues2[i]; tempValues[i] += tempValues1[i]; speed[i] += tempValues[i]; position[i] += speed[i]; speed[i] *= 0.1f; }}//Some codes were called to render everything.[/source]

But that would be very unrealistic and very unreasonable. Are there any other ways to make the deacceleration work nicely, behaving like the ball in the game Teeter for Android?

PARTNERS