Help with implementing smooth mario movement

Started by
11 comments, last by Orymus3 9 years, 10 months ago
Instead of having `leftSpeed' and `rightSpeed', combine them into a single `horizontalSpeed' (probably set to be `leftSpeed - rightSpeed'), and use that in your logic.
Advertisement
What alvaro said. Besides what happens when the user presses both a and d (left and right). With ur code, it'll move right. If u remove the else om the 2nd if, and use speed, the resulting speed will be 0.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

I generally handle the input as a vector.

Instead of direct cause to effect (movement occurs as you click), I use an additionnal layer:

When I click, I apply force in a direction.

I have a background process that tries to simulate inertia (progressively) by nullifying all vectors over time.

So, if I tap a direction, the move begins, and slows down into position.

You can see it in action here:

Notice how my 'direction' doesn't affect my vector and that it dies out of its own accord?

It is possible to apply something similar for your program.

Unfortunately, I am not familiar with the syntax you are using...

This topic is closed to new replies.

Advertisement