Math problem

minikrampan

Ultra Cool Member
Reaction score
28
Hey, I have 3 points that makes a triangle, I want a unit to slide from point one to two to three to one with a dynamic speed, The further away the points are the faster he slides. If they are closer, he slides slower.
so basicly between every point he should take 2 seconds to reach his target. So how to calculate this?
The unit will use Distance[4] as offset.
Code:
Set Distance[1] = (Distance between ABC[1] and ABC[2])
Set Distance[2] = (Distance between ABC[2] and ABC[3])
Set Distance[3] = (Distance between ABC[3] and ABC[1])
Set Distance[4] = ??
I was thinking somthing like 
Set Distance[4] = (((Distance[1] + Distance[2]) + Distance[3]) / 1500.00)
ABC is the points.

keep in mind that he slides every 0.01 second so the offset should be a low number.

Hope you understand what i mean im having trouble explaining stuff in english :/
 

Exide

I am amazingly focused right now!
Reaction score
448
You should first calculate the total distance:

Code:
Set Distance[4] = ((Distance[1] + Distance[2]) + Distance[3])

Then figure out how many 0.01 there are in 2 seconds. = 200.

So if Distance 1, 2 and 3 = 230 each (230 + 230 + 230 = 690)
And you want to move your unit this total distance 200 times, you should probably divide Distance[4] by 200. (690 / 200 = 3,45)

So in this case you move your unit at a speed of 3,45 200 times (for 2 seconds), and the unit should've moved all the way around your three points.

Code:

Code:
Set Distance[1] = (Distance between ABC[1] and ABC[2])
Set Distance[2] = (Distance between ABC[2] and ABC[3])
Set Distance[3] = (Distance between ABC[3] and ABC[1])
Set Distance[4] = ((Distance[1] + Distance[2]) + Distance[3]) / 200.00)

I might be wrong, though. :p
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Assuming it's a triangle with identical sides:

Offset would be

(Distance Between Points / Seconds to reach each point) * Interval

So in your case:

((Distance between ABC[1] and ABC[2]) / 2.0) * 0.01

If you want him to move through the whole triangle in 2 seconds:

(Distance between ABC[1] and ABC[2]) * 1.5 * 0.01
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top