As I promised here it is, and its easier than I thought:
To achieve a
constant speed we need several formulas.
speed = distance / time
From which we derive:
distance = speed * time
time = distance / speed
Of those two the later is the one we are most concerned with. Now lets take a look at the problem we are trying to solve. We have several waypoints and they are not all the same distance appart. But we want a boat to travel between them at a constant speed regardless of the distance between them. Now, we must supply to variables, #1 the speed at which we want to move (in quake units per second), #2 the distance between waypoints. The speed is easy, we just pick it. The distance is a little harder to figure. Think back to your geometry, now is when you wished you had paid attention, or you are glad that you did. To calculate the distance between to points on a 2-dimensional plane is simple, (read
^x as "raised to x-th power"
distance^2=(x1-x2)^2 + (y1-y2)^2. In a 3-dimensional plane we just add a 3rd part
distance^2=(x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2.
Now I could go on about how to access parts of vectors and all, but there is an easier way. It is called
vector_length. This handy little function takes a vector, the difference or sum of two origins, and returns the distance between the points (yes I know this is not the proper terminology for vectors, but it is clearer for the current purposes).
Great, now we have the speed and the distance, we just plug them into our formula
time = distance / speed, and "wa la" (I know my French stinks) we get the answer, or the time it will take two travel between the two points. Below is the mohaa script code to do what I've talked about.
Code: Select all
move_the_boat:
// The speed our boat will travel at in quake units
// per second, qps
local.speed=50
// $way1 -- our first waypoint
// $way2 -- our second waypoint
// Get the distance between them
local.dis=vector_length($way1.origin - $way2.origin)
// Calculate the time
local.time=local.dis/local.speed
$boat time local.time
// Tell the boat where to goto
$boat moveto $way2
// Move the boat. There are two ways to do this.
// 1) $boat waitmove
// This stops script execution
// till the boat is done moving
// 2) $boat move
// Continues with script exection
// while the $boat moves
$boat move
end
I hope this helps! If something isn't clear, let me know.