[Solved]Help With Player Movement

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Help With Player Movement

Post by raidho36 » 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.

MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: Help With Player Movement

Post by MasterLee » Wed May 17, 2017 4:27 pm

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

User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Help With Player Movement

Post by raidho36 » Wed May 17, 2017 4:42 pm

It's all fine and dandy until you remember that you have no control over dt.

User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help With Player Movement

Post by airstruck » Wed May 17, 2017 5:43 pm

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

uederson
Prole
Posts: 30
Joined: Mon May 23, 2016 7:59 pm
Location: Brazil
Contact:

Re: Help With Player Movement

Post by uederson » Tue May 23, 2017 3:41 am

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! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests