Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

Object .dir Property not working
show user profile  ccampbell
Hey Guys,

I am trying to get my newbox to create at the position of sphere1 and aim at sphere2.

if i create the box using maxscript at [0,0,0] and the dir facing sphere 2 everything works correctly. if i then Create or move the box to sphere 1 position and aim at sphere 2 the box now will not aim directly at the sphere. it appears to be offset almost.

Here is the code I'm using for this...

S1 = Sphere radius:4 pos:[-69.9137,0.0478439,0] -- create spheres
S2 = Sphere radius:4 pos:[70.5017,0.0083158,30]
completeredraw()

distObjs = distance S1 S2 -- get distance between spheres


--THIS CREATES BOX AT SPHERE 1 AND AIMS AT SPHERE 2 - DOES NOT WORK PROPERLY.
B1 = box length:2.000 width:2.000 height:DistObjs pos:S1.pos dir:S2.pos -- create box at sphere1 position and aim at sphere2 position
completeredraw()
converttomesh #(S1,S2,B1)

/*
-- THIS CREATES BOX AT WORLD CENTER -- WORKS AS IT SHOULD
B1 = box length:2.000 width:2.000 height:DistObjs dir:S2.pos -- create box at sphere1 position and aim at sphere2 position
completeredraw()
converttomesh #(S1,S2,B1)

*/




$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};



read 663 times
12/24/2011 2:55:15 AM (last edit: 12/24/2011 3:01:54 AM)
show user profile  Garp
I don't know if it was you but I remember answering the same question a few weeks ago.

If you say B1.dir = S2.pos, you're assigning to B1's dir the vector that goes from the origin to S2 (S2.pos being the offset of S2 from [0,0,0]).
To get the vector from S1 to S2, you need B1.dir = S2.pos - S1.pos.
Or, since B1 is at the same location than S1, B1.dir = S2.pos - B1.pos (once B1 is already created).




read 649 times
12/24/2011 5:46:34 AM (last edit: 12/24/2011 6:04:01 AM)
show user profile  ccampbell
Sweet! thanks Garp - It wasn't me but thanks for taking the time to explain it twice! I'll admit I didn't look through the forum for a similar issue before posting...I'll be sure to do so in the future.

Why is it you subtract the dir vector from the pos vector to counter the offset? i just want to understand for the future.




$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};



read 642 times
12/24/2011 7:33:27 AM (last edit: 12/24/2011 7:33:27 AM)
show user profile  Garp
I don't subtract dir from pos. I subtract one pos from the other and assign the result to dir.

Think of a vector as an offset.
When assigning a vector (a point3 value) to the dir property of an object, max internally uses the coordinates to compute the object's rotation, so that its Z direction is parallel to the vector and facing the same way.
If B1 is at the origin, you want the offset from the origin to S2 for B1 to face S2.
If B1 is at S1's location, you want the offset from S1 to S2, that is, what you need to add to S1's coordinates to get S2's coordinates. And that's S2.pos - S1.pos.




read 638 times
12/24/2011 7:59:29 AM (last edit: 12/24/2011 7:59:29 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org