Page 1 of 1

vector_length

Posted: Thu Apr 22, 2004 2:58 pm
by fuhrer
im trying to measure how far away a ball is from a waypoint (height only) as the waypoint stays in one position ( on the ground) and ther ball moves on all 3 axis.

when ive tried to do it im assumin its measuring the distance between the 2 origins in a straight line..

what i need is to have it only measure the distance in height. (Z axis?)

Code: Select all

$ball moveDown (vector_length ($ball.origin - $ball_stop.origin))
ive tried...

Code: Select all

 $ball moveDown (vector_length ($ball.origin[2] - $ball_stop.origin[2]))
must be doing something wrong, please help.

Posted: Thu Apr 22, 2004 3:56 pm
by lizardkid
you could do

Code: Select all

local.height = $ball.origin
and use local.height to comapre to the node. ignoring the two othr axis.

print

Posted: Thu Apr 22, 2004 4:40 pm
by tltrude
If you want to see what the value is, just print it to the screen.

iprintln (vector_length ($ball.origin - $ball_stop.origin))

Here is something i used.

$ball moveto ( ($ball_target.origin[0]) ( $ball_target.origin[1]) ($ball.origin[2]) )

Notice that the origin of the third number is different from the first two. That keeps it on the ground by not letting the third number change.

Posted: Thu Apr 22, 2004 4:44 pm
by lizardkid
you can print variables in MOHScript? cool.

Posted: Fri Apr 23, 2004 1:16 pm
by jv_map
Actually, I think the most straightforward way to do it is the following:

Code: Select all

// say you have two ents $a and $b with some origin
local.origin_a = $a.origin
local.origin_b = $b.origin

// the vector from a to b now is
local.vec_ab = local.origin_b - local.origin_a

// as you only want to measure the horizontal distance,
// let's set the vertical component to 0 :)
local.vec_ab[2] = 0

// now calc the distance :)
local.distance = vector_length local.vec_ab

death

Posted: Fri Apr 23, 2004 8:35 pm
by tltrude
There is a command that drops entities to the ground. I'm not sure if it will work for a script_object.

droptofloor( [ Float maxRange ] ) - drops the entity to the ground, if maxRange is not specified, 8192 is used.