2D Platform Movement [Solved]

Recommended Posts

[SOLVED] Is there a way to rename the topic? Someone else might find the solution helpful. Maybe.

Hello!

I'm working on a 2D platformer in java using LibGDX and over the past week I've been trying to get a good platform movement system working

So basically I have the following vectors: velocity, acceleration, friction & gravity.

What I want is, essentially the gravity being accumulated over time, not a constant gravity. (That way I can do things like, if you hit the ground with a y velocity higher than say 200, decrease the health of the player by some amount (based off of the velocity somehow).

I can do that, by simply doing: velocity += gravity * 0.01f and after one second, the Y velocity would be 240. I can then simply limit the Y velocity to say 400 to prevent the player from falling too quickly.

However, I also need to add the friction vector and when I do so, since it is higher than gravity * 0.01f it causes the gravity to become very weak.

Solution

So the solution is essentially to make sure the friction isn't too high and also only apply gravity when the player is in the air. Pretty simple.

Edited by afflicto

Share this post

Share on other sites

I fixed the title.  Post some code for the math you're using.  And welcome to software, where as soon as you walk away, post the question, get in the shower, or start driving, you figure out the answer.

Share this post

Share on other sites

And welcome to software, where as soon as you walk away, post the question, get in the shower, or start driving, you figure out the answer.

You forgot the part where you bang your head against a problem for hours, then go to bed feeling exhausted. Then, right before you fall asleep, you realize the problem, and now have to decide whether to get out of bed to fix it1, or try to sleep2 and fix it the next day3.

But even with all of that, it's still fun :)

1 ...and forget to go to bed again because of continued programming.

2 ...which often takes ages, because you're thinking through the solution and wanting to implement it.

3 ...hoping that you still remember the solution instead of just remembering the fact that you had a solution.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

• Forum Statistics

• Total Topics
628350
• Total Posts
2982211

• 10
• 9
• 24
• 11
• 9