Thread: basics MAXScript
View Single Post
  #5 (permalink)  
Old 27th April 2007
Ceryni's Avatar
Ceryni Ceryni is offline
Tutorial contributor
Join Date: Jan 2007
Location: Uk
Posts: 67
Thanks: 0
Thanked 4 Times in 4 Posts
Send a message via MSN to Ceryni Send a message via Skype™ to Ceryni
MAXScript Planet animation

If you read the basics section this should make more sense to you and by reading the following script should understand (roughly) how this is working.

MAXScript and the listener are different programs. the listener will execute the funtions immediatly, as previously stated. MAXscript will not execute any functions until u wish to "Evaluate" it. to do this i recommend having Listener AND MAXScript open. to run the script and create the objects >>"file" > "evaulate all" or "Ctrl E"
type in MAXScript and the Listener will give you the feedback, showing where you've got it right and where the mistakes are.
MAXScript is located in the same pulldown tab as Listener. select "New Script"

This Tut will show you how to Animate a planet in orbit around a sun.

Creating the Sun, and the Planet

--Create a Yellow sun, with radius 10
sun = sphere radius:10.0 \
--
set the color of the sun using RGB in square brackets.
Wirecolor:[255,255,50] \
--name the sphere "sun"
name:"sun"

Next step is to create a Planet, and move that planet into an orbit around the sun.

--create a circle for the planets path
orbit1 = circle radius:50.0 name:"orbit"

--create a small red planet and move it to the circle, color it red and name it.

Planet1 = sphere radius:2.0 \
Wirecolor:[200,0,0] \
--the "\" ends a line in this circumstance
name:"planet"

--move planet onto the orbit circle
move planet1 [50,0,0]

Apply a Path Deform Modifier ( path restraint works to )

--create a PD mod, choose "orbit1" to be the path and "Y_axis" to be the axis.
pd1 = pathdeform path: orbit1 axis:1
addmodifier planet1 pd1
--rotate the orbit, just to give it a bit more effect.
rotate orbit1 (quat 5.0 y_axis)
i used Quaterniun angles here as its easier to use that for the rotation then the euler angles. altho i did have to spend 10 minutes working out how to use them enough for it to work. some reason Euler doesnt work here.

this is where math does my head in. using trigonometry we need to move the planet so it remains on the orbit when rotating.

-- Note - 50*sin(5.0) = 4.36 (5.0 is the angle of the orbit, gives me X coordinate)
--Note - 50 - (50*cos(5.0)) = 0.19 ( the x coordinate*cos*angle gives me Z coordinate
move planet1 [-0.19,0,-4.36]

If you did all this correctly, you can now press "evaluate" or "Ctrl E" and the entire scene will be created in front of your eyes.



Animate the Scene.

Select the planet and turn on the "AutoKey",
Move the Timeslider to frame "100"
Click on the modifier panel and under PathDeform change percent to "100"
Turn off "Autokey"

Reselect the first keyframe and right click the keyframe ruler and select "Planet1: percent along path"
Set the In and Out Curves to "Linear"



Play your Animation!






Reply With Quote
The Following User Says Thank You to Ceryni For This Useful Post:
CHALLENGER (8th October 2007)