playMaker

Author Topic: please help with a distance/speed calculation  (Read 2976 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
please help with a distance/speed calculation
« on: October 31, 2013, 11:15:24 AM »
Hi I need some help with a calculation I need for a timer I have counting down.
Basically, I have a player that moves around using a speed variable and a simple countdown timer. Also a distance variable that checks from player to a home base object.
And what I need using these 3 variables is to check what would be the latest time left for the player to make it back to base.
Can someone help me out I'm pretty sure it's a simple calculation, but my math isn't the best ;-)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: please help with a distance/speed calculation
« Reply #1 on: October 31, 2013, 02:55:40 PM »
Hi,

 ok,

 the distance is equal to the speed*time

 so if you know the remaining distance and the speed, and want to know the time it will take:

time = distance/speed


Try this, and let me know how it goes,

bye,

 Jean


Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: please help with a distance/speed calculation
« Reply #2 on: November 01, 2013, 11:06:29 AM »
Hi,

 ok,

 the distance is equal to the speed*time

 so if you know the remaining distance and the speed, and want to know the time it will take:

time = distance/speed


Try this, and let me know how it goes,

bye,

 Jean

Thanks Jean. So I have a time float variable, a distance float and speed float variables.

On the object that I want to move back to base in the time left, I have a FSM -

Get Distance (store result to distanceToBase)

Float Operator (float 1 = distanceToBase)
                     (float 2 = speed)
Operation        (divide)
Store Result     (my time float?) or a new float?

So, if I have that setup right, (do I store the result in the variable I'm using for time, or in a new float?)
I need to SetDestination in the Navmesh, to base at some point, but I dont know how to use that stored result for what I'm after.
Also, to add to the problem, I'm using a terrain with objects that are set as static.  So, whatever time it will take to return back to base, it will always be too short because the route back will not be a straight line.
thanks for any help.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: please help with a distance/speed calculation
« Reply #3 on: November 04, 2013, 05:28:58 AM »
Hi,

--  Using the action "getAgentRemainingDistance" you'll know the actual distance left for the current path/destination it's seeking.
-- Using the action "GetAgentVelocity" you'll know the current speed.

 Then you can work out the time left.

You need to store the result in a float for sure, call it "Time left" or something, then you can display that "time left" value to the user in your UI.

bye,

 Jean


Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: please help with a distance/speed calculation
« Reply #4 on: November 05, 2013, 03:53:18 PM »
Hi,

--  Using the action "getAgentRemainingDistance" you'll know the actual distance left for the current path/destination it's seeking.
-- Using the action "GetAgentVelocity" you'll know the current speed.

 Then you can work out the time left.

You need to store the result in a float for sure, call it "Time left" or something, then you can display that "time left" value to the user in your UI.

bye,

 Jean

Thanks Jean. Where can I find that agent action?
It's used for a NPC so I want it to set the navmesh gohome when the distance is too far away from the base.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: please help with a distance/speed calculation
« Reply #5 on: November 06, 2013, 12:42:57 AM »

Splankton

  • Sr. Member
  • ****
  • Posts: 268