2D Platform Movement [Solved]

Started by
1 comment, last by Lactose 9 years, 11 months ago

[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.

Advertisement

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.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532


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.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement