How to achieve the effect like Path Constrain using MAXScript?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2009   #1
Wink How to achieve the effect like Path Constrain using MAXScript?

Hello everyone!

I wanna animate a car.

I want to make the keys of position manually, and generate the car's rotation automatically.
I mean, first turn on Auto Key, second move the car to generate position keys, then the car rotates to follow the trajectory automatically, which is just like the effect of Path Constrain.

How can I achieve this?

Thank you!
Longing for answer!
 
Old 03 March 2009   #2
That is just a random shot now, but I think you might be able to do that with a Rotation Script Controller, where you specify the Orientation Vector by the difference of the Position Vector of the current frame and the Position Vector of an earlier frame.
 
Old 03 March 2009   #3
Check out Shape Common Properties in the help.

You can use lengthTangent to get the directional vector for the tangent at a certain percentage along a spline's length. Use this to then generate a rotation value.

You can also use lengthInterp to get the position value of a certain percentage along a spline's length.

Hope that helps.
 
Old 03 March 2009   #4
Red face Thank you

Thank you for your reply.

But I don't want a spline. I just wanna move the car manually not using a spline.
 
Old 03 March 2009   #5
so basically you'd want the equivalent of...
1. going into trajectories mode
2. converting the trajectory to a spline
3. setting that spline as a path constraint with 'follow' on
4. bake the rotation out to actual keyframes
?

(I, too, thought he just meant he didn't want to use a path follow constraint - while still following a path, leading to this script controller >_<

nearestParam = nearestPathParam spl 1 obj.pos steps:200
obj.pos = pathInterp spl 1 nearestParam
obj.dir = pathTangent spl 1 nearestParam
1

)
 
Old 03 March 2009   #6
I think I know what you are going for, and I have done it before on my reel (you can check it out here, near the end of the reel: http://dimitrykachkovski.com/Kachko...ry_DemoReel.mov)

What you want is to get he motion of the object, and based on it's previous position get the directional vector. From this directional vector you can get the proper rotation of the car.

f = currentframe
LastF = currentframe - 1
dirVec = normalize ((at time f $.pos) - (at time LastF $.pos)


This will basically get you the direction, and then you just need to normalize the entire matrix through consecutive cross products.

Hope it helps.
 
Old 03 March 2009   #7
Ah okay, I didn't realize. I guess I paid too much attention to the subject line.

In that case, Phillip and Dimitry have provided some very good approaches. I would go down that path. (pun intended?)
 
Old 03 March 2009   #8
Talking

Thank you for your answers. Could you show me more details about your method? ĎCause I still donít get how to turn your method into an executable MAXScript.
And hereís my script:


-- create an object
obj = box width:17 length:42 height:14
setTrajectoryOn obj true

-- animate the objectís position
animate on
(
at time 33 obj.pos = [50,100,0]
at time 66 obj.pos = [120,13,38]
at time 99 obj.pos = [100,-24,0]
)


-- automatically rotate the object
......(script that I donít know how to achive)


You can see I wanna rotate the object to follow its trajectory.
This is what I wanna do.


 
Old 03 March 2009   #9
No, not a script...a 'Script Controller'

Go to the Curve Editor or the Motion Pannel and assign a 'Rotation Script' to the Rotation of the object. In there you write the code.
 
Old 03 March 2009   #10
Red face

Originally Posted by Piflik: No, not a script...a 'Script Controller'

Go to the Curve Editor or the Motion Pannel and assign a 'Rotation Script' to the Rotation of the object. In there you write the code.



Yeah,thank you!
But what does the Script should be?
Could you show any detail?
 
Old 03 March 2009   #11
Sorry for taking so long. I think I might post a small tutorial on my blog in the future just for the hell of it. But basically I make it in a way where I have a Custom attribute on the object that is rotating. The code for the attribute is this:
CustAttr = attributes RotVal 
( 
   parameters RotValP 
   ( 
      Rot type:#float default:0 
   ) 
) 
custattributes.add $.baseobject CustAttr


When it comes to the actual script controller code, this should be it:
if currentTime == 0f do 
( 
Obj.RotVal.Rot = 0 --Obj should be a variable added in the Script controller pointing to the object that holds the custom attribute
) 
p1 = at time currentTime Obj.pos 
p2 = at time (currentTime-1) Obj.pos 
dist = distance p1 p2
cir = (2*pi)*Obj.radius
ang = dist/cir
Obj.RotVal.Rot += degtorad(360*ang)


Sorry for taking so long, busy days at work
 
Old 03 March 2009   #12
Red face

Thanks for your reply during the busy work!

But I'm cofused at this place:
cir = (2*pi)*Obj.radius

What does Obj.radius mean?
I guess that it's the radius of the object's trajectory,but there's no such property for a node as far as I know.

And using your method the object always rotates for a plus number,but sometimes it may rotate for a negative degree like -70.
So how do we get that the angle of its rotation is a plus number or a negative one?
 
Old 03 March 2009   #13
O man, hahahaha, I completely messed this one up So sorry man, I posted a completely wrong part of what I wanted to show. This is for the wheel rotation, not for the actual object rotation. Sorry about that. So here goes my second attempt
if currenttime != 0f then --I prefer to have the rotation neutral at frame 0
     (
     YVec = normalize (Cnt.pos - (at time (currenttime-1) Cnt.pos)) --get normalize
     ZVec = [0,0,1] --this is needed for a temporary up vector calculation
     XVec = cross YVec Zvec --cross product of Y and Z gives us X
     ZVec = cross XVec YVec --cross product of X and Y gives the orthogonal Z
     tm = (matrix3 XVec YVec ZVec Obj.pos) -- this is our objects transform
     tm.rotationpart --get the rotational part
     )
     else
     (
     quat 0 0 0 1
     )


What I gave you was basically another part of having a car set-up, which would be the wheel rotation. Once again sorry shame on me! Anyways, this should do it for you

EDIT: In fact, lemme attach the max file so that you can see it in action! (Its in Max 2k8 format)
Attached Files
File Type: zip AutoRotation.zip (13.6 KB, 55 views)

Last edited by Dimich : 03 March 2009 at 10:25 AM.
 
Old 03 March 2009   #14
Thumbs up

Thank you!

I'm learning your method which looks very cool.
 
Old 03 March 2009   #15
Talking

I got it, man!
The Vector Cross Product is very cool!
And I've also understood the meaning of Matrix3!
Thank you!
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:58 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.