Jump to content

  • Log In with Google      Sign In   
  • Create Account

2D Platform Movement [Solved]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 afflicto   Members   -  Reputation: 127

Like
1Likes
Like

Posted 05 May 2014 - 10:33 PM

[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, 05 May 2014 - 11:26 PM.


Sponsor:

#2 Glass_Knife   Moderators   -  Reputation: 4996

Like
1Likes
Like

Posted 06 May 2014 - 09:49 AM

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"
Indie Game Programming

#3 Lactose!   GDNet+   -  Reputation: 3818

Like
4Likes
Like

Posted 06 May 2014 - 10:10 AM


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS