Page 2 of 2

Re: Help With Player Movement

Posted: Wed May 17, 2017 1:37 pm
by raidho36
Um, no? It leads to higher value because the movement function is defined not to stop unless position value is at least X, and X is updated in discrete but finite and randomized steps, so either your dt's will land you at exactly right coordinate, which is extremely unlikely, or the function will issue another step forward, which conversely is almost guaranteed to overshoot.

Re: Help With Player Movement

Posted: Wed May 17, 2017 4:27 pm
by MasterLee
raidho36 wrote: Wed May 17, 2017 1:37 pm Um, no? It leads to higher value because the movement function is defined not to stop unless position value is at least X, and X is updated in discrete but finite and randomized steps, so either your dt's will land you at exactly right coordinate, which is extremely unlikely, or the function will issue another step forward, which conversely is almost guaranteed to overshoot.
First you said problem with integration is only when you reach the exact spot.
Now you said exactly the opposite!

Ok here i show you.

v=10
Maybe stop on x=30 slightly as original post
with dt=1
t=0, x=0
t=1, x=0+dt*v=10
t=2, x=10+dt*v=20
t=3, x=20+dt*v=30
t=4, x=30
but now with dt=1.1
t=0, x=0
t=1.1, x=0+dt*v=11
t=2.2, x=11+dt*v=22
t=3.3, x=22+dt*v=33
t=4.4, x=33
As you can see at t=3.3 the formular would be wrong
it should be broken into:
t=3, dt=0.8, x=22+0.8*v=30
t=3.3, dt=0.3 x=30

Re: Help With Player Movement

Posted: Wed May 17, 2017 4:42 pm
by raidho36
It's all fine and dandy until you remember that you have no control over dt.

Re: Help With Player Movement

Posted: Wed May 17, 2017 5:43 pm
by airstruck
@MasterLee, when I said "there's nothing wrong with integration" I was referring specifically to pos=pos+vel*dt. Since there's nothing else in the code to indicate that something else happens after the thing "hits the wall" at 32px, we don't know whether it matters if there's some "extra dt" that gets discarded. This could be the end of the simulation for all we know (it's clearly just example code anyway).

Let's assume that something else does happen; maybe the thing bounces off the wall and its velocity is inverted. In that case, you could calculate how much "extra dt" was left, and add it to the dt in the first step of traveling back the other direction. In that case nothing would happen late, and the integration formula pos=pos+vel*dt would remain the same (remember dt is our modified value, the dt for this tick plus the "extra" dt from the tick where it hit the wall). Or you could apply the left-over dt in the same tick where the thing hits the wall, you get the idea.

We don't know whether any of that matters. The OP could be working on a turn-based game, where nobody cares if the next turn happens a tiny fraction of a second late.

Re: Help With Player Movement

Posted: Tue May 23, 2017 3:41 am
by uederson
Hi all! Bellow is a link to a little video showing how I am moving the player using the tips you guys gave me here!
https://drive.google.com/file/d/0BxWloK ... p=drivesdk

It moves 32 pixels each time I touch the directional arrows.

Thank you again! :)