Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About TheCalm

  • Rank
  1. TheCalm

    Jumping for AI in my platform game

    Thanks The problem is that even though i set a constant "g" and a constant "V0y" the jump doesnt seem to land on the exact position i want to. Sarah seem to land to far :/
  2. TheCalm

    Jumping for AI in my platform game

    Thanks! I've been trying to get a good formula from what i know. But i cant get it to be exact. The problem is that it seem to be dependent on to many variables. For instance we have one formula that says that the speed in the x-axis is the same, it never changes. So if we have that in mind we know that: X (a distance) is equal to V0 * cos(a) * t Where V0 is the starting velocity, the cos(a) i the cos for the angle at the start and t is the time it takes to travel the distance in x. Okey, so we can rewrite cos(a) to be V0x / V0 which leads to "x = V0 * (V0x / V0) * t". We see that we can take away the "V0" part leading us to get: "x = V0x * t". This is good, since I know my velocity in x to be the same all the time which means that the v0x is the same. So we know x, since we have a waypoint that keeps track of the points we want Sarah to go. Perfect you might think! But it is here that it gets tricky. Why? I'll try to explain. So say that x is 200. That means Sarah is supposed to jump 200 pixels from her place here. Her speed in the x-axis must be atleast 11 (since my character im steering has 10 in speed, and i want Sarah to be faster then my character). So this will give us the time for the jump. In this case this means that the distance of 200 pixels with a speed of 11 pixels per update (i will refer the time as how many updates something will take. And my FPS is locked at 60 FPS, giving us 60 updates per seond. If you would rather count it as pixels per second or something). Anyhow! This means that the jump will take 200/11 = 18.18181818... ~18.2 updates. We also know that "y = V0 * sin(a) * t - ((g * t^2) / 2) Where y represents the point at any time in the jump in the y-axis, the g is the gravity and the sin(a) is sin of the angle. We can rewrite sin(a) as V0y / V0. And as above this will lead to "y = V0y * t - ((g* t^2) /2). Now we have three loose variables. The starting velocity V0y, the gravity g and the y. But if we say that we will take the point where y is the highest, then we know that would be exactly the half of the time (18.2 updates). And say that we take y to be "the difference in y + 128". Meaning if sarah will jump in the same y height, her maximum height will be 128 pixels above her position now. If she were to jump to a platform 64 pixels above her, her maximum height would be 128+64 = 192 pixels and so on. But for now, lets just focus on a jump 200 pixels away in the same y-height. This will give us y = 128 at the time of (18.2 / 2) = 9.1. But the problem now is that we still have two loose variables, g and V0y, right?
  3. TheCalm

    Jumping for AI in my platform game

    Thx for the reply! Though i'm afraid that's not my problem. I already have a class for the waypoints who contains a position-vector and a bool that keeps track if i need to jump. The problem is the get a formula to get Sarah to jump and land exactly on the position :/ Cheers!
  4. TheCalm

    Jumping for AI in my platform game

    I'm really getting frustrated here guys :C Doesn't anyone have any idea? :/ Cheers, TheCalm
  5. Hi GameDev! This is my first post here ^^ Now to le business. The problem: I have a side-scrolling-platform-game where you have 2 characters. The first one is the one you are in controll of. He is ready and done with all the controlls. Then we have the enemy, lets call her Sarah. Sarah will be at the left on the screen throwing stuff at you, and when you get close enough she will either walk or jump to the next waypoint in her waypointlist.After that she will continue to throw stuff at you. That is, untill you get close enough, then she will either walk or jump to the next waypoint and so on and so on. My problem here is that i want to create a code for her jumping. i will have set of waypoints which will have 1) coordinates for the next place she wants to go and 2) if a jump is needed or not. But i cant seem to find anywhere a similair code for that. I've looked at parabola equations (http://www.wolframalpha.com/input/?i=y+%3D+%28x%5E2%29+%2F+%284+*+a%29+where+a+is+-1 and http://www.wolframalpha.com/input/?i=parabola+formula) And also the throwing equation you learned in physics courses at high school (http://www.wolframalpha.com/input/?i=y+%3D+%28V0+*+sin%28a%29+*+t%29+-+%28%28g+*+t%5E2%29+%2F+2%29) But I really can't seem to get a code where she jumps EXACTLY to the place i have in her waypoint-vector.. So the variables i have from the beggining och the jump are: The distance in x. The distance in y at the top (i will have the difference in Y in the the platforms + 128 pixels as a top for the parabola). Asides from those two, i have tried to experiment things like starting veclocity in x and y, gravity and at which time (in frames) the jump would take. Can somebody please give me either a code for this, a good site about this or something else useful i would be forever grateful! Cheers! /TheCalm
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!