How to smoothly change speed of an object? #2554
-
Every object takes time to slow down right? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Beta Was this translation helpful? Give feedback.
-
rather than setting an object's velocity directly you should use acceleration and drag. I see you're just setting a speed value, I assume that sets velocity, instead set acceleration, and cap it with maxVelocity this project calculates acceleration and drag based on how long it should take to speed up to max speed and how long to come to a full stop (Source linked in the page) Here's the game's actual code to solve for maxVelocity, acceleration and drag. Note that maxSpeed is determined by how far the player is supposed to be able to jump. |
Beta Was this translation helpful? Give feedback.
rather than setting an object's velocity directly you should use acceleration and drag. I see you're just setting a speed value, I assume that sets velocity, instead set acceleration, and cap it with maxVelocity
this project calculates acceleration and drag based on how long it should take to speed up to max speed and how long to come to a full stop (Source linked in the page)
https://www.newgrounds.com/portal/view/723552
Here's the game's actual code to solve for maxVelocity, acceleration and drag. Note that maxSpeed is determined by how far the player is supposed to be able to jump.
https://github.com/Geokureli/Dial-A-Platformer/blob/master/source/art/DialAPlatformer.hx#L242-L265