[Closed] Finding distance between objects
Hey all,
I know this is a relatively easy one for you guys but it will help me in my learning a lot. Basically i want to be able to select two point helper objects and create a third point helper exactly midway between them. I understand, conceptually what needs to be done but having trouble with the best way to implement it!
Thanks for in advance for any help!
pointA = $Point01
pointB = $Point02
p3Pos = (pointA.pos + pointB.pos)/2
point pos:p3Pos
Build the sum of both objects positions and divide it by two to get the middle. Instead of referring to Point01 and Point02 you can assign [b]selection[1][/b] and [b]selection[2][/b]. You'll need some error checking if you really want to use it though.
And here’s the pretty version:
(
rollout main "Main"
(
pickbutton pick1 "Object #1" across:2
pickbutton pick2 "Object #2"
button doit "You can do it!"
local obj1, obj2
on pick1 picked obj do
(
if obj != obj2 then
(
pick1.text = obj.name
obj1 = obj
)
)
on pick2 picked obj do
(
if obj != obj1 then
(
pick2.text = obj.name
obj2 = obj
)
)
on doit pressed do
(
if obj1 != undefined AND obj2 != undefined then
(
point pos:((obj1.pos + obj2.pos)/2)
)
)
)
createDialog main
)
MXS Help -> Node Common Properties, Operators, and Methods
[left]distance <node> <node>
[/left]
[left]Computes the distance between the pivot points of the two specified nodes.
[/left]
If you need to place it any where along the path you can use something like this.
p3=(p2-p1)*t+p1
Where t is a value from 0 to 1. 0 being the position at p1 and 1 being the position at p2 and .5 would be half way between.