Jump to content
  • Advertisement
Sign in to follow this  
Silbrery

Calculating speed based on travel distance

This topic is 2888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I have the following problem. There are two(or more) objects that follow a path through a level starting at different positions. Now those objects should theoretically be able to hit each other when they cross paths, no matter at what position in the level they started. There is a calculation i'am missing here to accurately set the speed based on the overall length of the path. Just setting the speed to pathLength*scale doesn't give correct results and the objects are missing each other.

Any help or pointer in the right direction would be appreciated.

Edit: Sorry i think i postet this in the wrong forum, could someone move this to Math and Physics ?

Share this post


Link to post
Share on other sites
Advertisement
I don't know if I understand you correctly, but I'll try to explain the answer to what I believe you are asking. It is quite simple actually.

Take a look at HelpfulPic.png, it names a few things of interest. First there is POI, a shorthand for Point Of Intersection. You must find the point of intersection between path 1 and path 2. Then there is len1, the length from the start of path 1 to the POI. Same with len2, the length from the start of path 2 to the POI. There is one variable missing though, time. You must set an arbitrary amount of time that you would like to pass before the two objects collide, for example 2.0 seconds or 4 minutes, etc. With these variables you can use the following equations:

Object1_Speed = len1 / t
Object2_Speed = len2 / t


These two speeds will make it so object 1 and object 2 collide.

Share this post


Link to post
Share on other sites
Yea time it is what i was missing. What i forgot to say is that those two objects might start at different times(1-2 seconds difference), so i need to take this into account.
Thank you very much!

Share this post


Link to post
Share on other sites
t in the formula doesn't have to be the same for all objects it needs to be (tcollided - tstarted) aka how long this specific object was traveling.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!