Skip to content

How to smoothly change speed of an object? #2554

Answered by Geokureli
NikRetaNCAM asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@NikRetaNCAM
Comment options

@Geokureli
Comment options

@NikRetaNCAM
Comment options

@Geokureli
Comment options

@NikRetaNCAM
Comment options

Answer selected by NikRetaNCAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants