Notifications
Clear all

[Closed] 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!

21 Replies

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.

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.

Thank you for your reply.

But I don’t want a spline. I just wanna move the car manually not using a spline.

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

)

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/Kachkovski_Dimitry_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.

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?)

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:

[color=lime]– create an object
obj = box width:17 length:42 height:14
setTrajectoryOn obj true
[color=lime]– animate the object’s position
animate on
(
at time 33 obj.pos = [50,100,0]
at time 66 obj.pos = [120,13,38]
[color=deepskyblue]at [/color]time 99 obj.pos = [100,-24,0]
) [/color]

[color=lime]– automatically rotate the object
…(script that I don’t know how to achive) [/color]

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

[/color]

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.

1 Reply
(@jausn)
Joined: 10 months ago

Posts: 0

Yeah,thank you!
But what does the Script should be?
Could you show any detail?

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 :argh:

1 Reply
(@jausn)
Joined: 10 months ago

Posts: 0

I’ve run with this script for the wheel and I figured that the wheel always rolled in one orientation whenever you played the animation forward or reverse.
You’ve ever found this problem?

Page 1 / 2