How do I Predict Movement?

0 favourites
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • Hello,

    I have this diagram and I'm trying to work out the solution.

    I have a ship, traveling at 10 pixels per second with an angle of 315 degrees (North East)

    His position:

    X: 5000

    Y: 528

    How do I calculate where he'll be in 30 or so seconds?

    Keep in mind we're in C2 and he's about to hit 0y and go into the negative.

  • The easiest way would be to place another object at its location then use the move at angle action, and have it move 10*NumberOfSeconds at 315 degrees. Keep in mind the location might not be exact depending on the fluctuations of dt if you're using it for physics.

  • It would need a mathematical solution. The server needs to calculate this in the end.

    We have the speed, it's starting point, we need a way to figure out it's ending point 30 or so seconds later.

  • Basically this:

    newX = oldX + 10*cos(angle)

    newY = oldY + 10*sin(angle)

    But depending on the programming language you may need to convert the angle from degrees to radians.

  • It's a start, but where does the 30 seconds fit in? We're using c2 for this example really.

    Where will the dot be 30 or so seconds later?

  • I'd like to know if this is going to be school assignment, commercial product or hobby project?

  • I've got:

    NewX = OldX + (30 * 10)

    NewY = OldY - (30 * 10)

    But this would only work if the dot is heading 315 degrees. I'll need to put more thought into what I'm trying to do.

  • oldX + cos(yourangle) * (30*10)= new x

    oldY + sin(yourangle) * (30*10)= new y

  • What newt said, I always forget something if I don't actually implement it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • oldX + cos(yourangle) * (30*10)= new x

    oldY + sin(yourangle) * (30*10)= new y

    Cool, will this work if we change the heading from 315 degrees to 90?

  • Should work for what ever angle you want to point at.

    Give or take some dt. Just so long as its a straight line.

    You'll have to call R0J0hound back for curves.

  • oldX + cos(yourangle) * (30*10)= new x

    oldY + sin(yourangle) * (30*10)= new y

    Should work for what ever angle you want to point at.

    Give or take some dt. Just so long as its a straight line.

    You'll have to call R0J0hound back for curves.

    It's not adding up see below:

    NewX = 2000 + cos(95 degrees) * (30*10) = 1973.85327718

    NewY = 528 + sin(95 degrees) * (30*10) = 826.858409428

    So after traveling for 30 seconds on a heading of 95 degrees, the dot will be at 1973, 826 ?

    The NewX seems to be incorrect as the dot is going South East, the X value should be increasing not decreasing.

  • The math as newt wrote works. As you wrote it is incorrect, you added some parenthesis that weren't there.

    Edit:

    Well, since I posted you edited your post or some nonsense like that. So now the formula is correct and the numbers look to be in the range you'd expect. If you want to be more sure of the formula then I recommend reading up on converting polar coordinates to Cartesian coordinates.

  • Where?

  • Its kind of hard to know whats happening as I don't know how you've got the movement set up.

    You say physics, but that would lead me to believe its not a constant speed. So the 10 * 30 may be questionable.

    Or perhaps the angle you are using is off as well.

    All I can say is a rate of 10 pixels per second for 30 seconds should get you a distance of 300 pixels, and and angle of 95 would point south east if the origin was the east, or that way ->.

    Thats the origin C2 uses.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)