Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411716 Posts in 69402 Topics- by 58450 Members - Latest Member: FezzikTheGiant

May 21, 2024, 08:05:17 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Calculate max speed
Pages: [1]
Print
Author Topic: Calculate max speed  (Read 1448 times)
TeaAndBiscuits
Level 0
***


View Profile
« on: June 13, 2010, 05:37:56 AM »

Hi guys,
I have a little maths question for you.

My entities move around using some basic physics in the form of
Quote
vel.x += stepSize * timeElapsed;
pos.x += vel.x;
vel.x *= friction;
NOTE : stepSize, timeElapsed and friction are effectively constant

It would be really useful to know the top speed the entity will be able to reach (roughly no need for 100% accuracy here!)

After a few beers last night my brain isn't able to deal with this today   Tired

cheers
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #1 on: June 13, 2010, 06:17:57 AM »

velX before  = velX after
i.e.

velX = (velX + stepSize * timeElapsed) * friction;

Rearranging

velX = stepSize * timeElapsed * friction / ( 1 - friction)
Logged
TeaAndBiscuits
Level 0
***


View Profile
« Reply #2 on: June 13, 2010, 06:27:36 AM »

Thanks for the reply!

But can you explain this a little bit more please? My brain still isn't working, time for a brew I think  Coffee
Logged
TeaAndBiscuits
Level 0
***


View Profile
« Reply #3 on: June 13, 2010, 06:33:11 AM »

EUREKA!

I get it now. Coffee for the win

Many thanks
Logged
PleasingFungus
Level 7
**



View Profile WWW
« Reply #4 on: June 13, 2010, 10:10:11 PM »

...shouldn't the second line (of the original code) be "pos.x += vel.x * timeElapsed"?
Logged

Finished games: Manufactoria! International King of Wine!
And others on my site.
TeaAndBiscuits
Level 0
***


View Profile
« Reply #5 on: June 14, 2010, 07:49:00 AM »

Really?
Velocity is a product of distance and time so then multiplying the velocity by time wouldn't work.

Also Velocity accumulates over many frames so to then multiply the total velocity by the time step would make funky things happen.
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #6 on: June 14, 2010, 08:28:07 AM »

no, cavalcade is right. velocity = distance / time.
Logged
bateleur
Level 10
*****



View Profile
« Reply #7 on: June 14, 2010, 09:06:34 AM »

To put things in more intuitive terms, if you run for twice as long wouldn't you expect to travel twice as far?
Logged

TeaAndBiscuits
Level 0
***


View Profile
« Reply #8 on: June 15, 2010, 01:01:44 AM »

WOOPS!  Embarrassed

Got myself into a right pickle. Thanks for the correction, looks like I need to fix this then. Damn.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic