The Daily Click ::. Forums ::. Klik Coding Help ::. Need help with speed calculation
 

Post Reply  Post Oekaki 
 

Posted By Message

Toni Montano



Registered
  13/10/2012 05:35:39
Points
  15
29th September, 2014 at 29/09/2014 23:59:00 -

Hi,

I'm desperate to calculate what my speed will be in future time.
Example:
Always:
- Set X_Vel to X_Vel( "Player" )+(Cos(Rotation( "Player" ))*Acceleration( "Player" ))
- Set Y_Vel to Y_Vel( "Player" )-(Sin(Rotation( "Player" ))*Acceleration( "Player" ))
- Set Current_Speed to Min(Sqr((X_Vel( "Player" ) pow 2)+(Y_Vel( "Player" ) pow 2)), Max_Speed( "Player" ))
- Set Move_Angle to ATan2(0-Y_Vel( "Player" ), X_Vel( "Player" ))
- Set X_Vel to Cos(Move_Angle( "Player" ))*Current_Speed( "Player" )
- Set Y_Vel to 0-(Sin(Move_Angle( "Player" ))*Current_Speed( "Player" ))
- Set X_Pos to X_Pos( "Player" )+X_Vel( "Player" )
- Set Y_Pos to Y_Pos( "Player" )+Y_Vel( "Player" )
- Set X position to X_Pos( "Player" )
- Set Y position to Y_Pos( "Player" )

Now I would like to calculate what speed or what x and y position will be in future time, for example: in 10 miliseconds time in future or in 50 miliseconds time.

thx for answers

Edited by Toni Montano

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
30th September, 2014 at 30/09/2014 02:05:19 -

You're going to have to use the brute force method - put all that into a fastloop, and then run it to "simulate" what will happen.
eg. If your game runs at 50FPS, the time between frames is 1/50th of a second (ie. 20 milliseconds) - so to find the speed in 40 milliseconds, you'd run the fastloop twice.

It's way too complicated to do any other way.

Edited by Sketchy

 
n/a

Toni Montano



Registered
  13/10/2012 05:35:39
Points
  15
30th September, 2014 at 30/09/2014 10:50:12 -

Thx for reply Sketchy ,

I found a solution for this.

You give me a great information: If your game runs at 50FPS, the time between frames is 1/50th of a second (ie. 20 milliseconds).

What i did is:
I tested 2 peers on the same computer and realize that i see peer 0.06 behind where he actually is. So what i did is that I create a new player (player 2) and I set X_Vel and Y_vel for Player 2 with X_Vel and Y_vel formulas from Player 1 and I just multiply acceleration. so what i did is:
- Set X_Vel( "Player 2" ) to X_Vel( "Player" )+(Cos(Rotation( "Player" ))*(Acceleration( "Player" ))*12)
- Set Y_Vel( "Player 2" ) to Y_Vel( "Player" )-(Sin(Rotation( "Player" ))*(Acceleration( "Player" ))*12)
- Set X_Pos( "Player 2" ) to X_Pos( "Player" )+X_Vel( "Player 2" )
- Set Y_Pos( "Player 2" ) to Y_Pos( "Player" )+Y_Vel( "Player 2" )
- Set X position( "Player 2" ) to X_Pos( "Player 2" )
- Set Y position( "Player 2" ) to Y_Pos( "Player 2" )

Why i multiply with 12? I figured out that if peer is 0.06 behind where it actually is and 1 frame is 20 miliseconds i need to have 12 bigger acceleration. When i tested now i have 0.00 right spot

If i will have time i will write an article of how i found a solution to have the same position on different computer using Lacewing.

THX again Sketchy

Edited by Toni Montano

 
n/a
   

Post Reply



 



Advertisement

Worth A Click