need help with animation looping

need help with animation looping

Anonymous
Not applicable
410 Views
1 Reply
Message 1 of 2

need help with animation looping

Anonymous
Not applicable

 

Could use some help. This is the current script. Question underneath it.

 

ResetMaxFile #noPrompt
SULengthofAnimation = 100
AnimationRange = Interval 0 SULengthofAnimation
 
c = sphere name: "foo" radius: 5
c.position.controller = Position_XYZ ()

	 animate on 
          for t in 0 to SULengthofAnimation by (.10 * SULengthofAnimation) do
	           at time t
                      c.pos.z +=  (.10 * SULengthofAnimation)     ----<<--point of interest/problem for this question

 How can I make c.pos.z NOT move 10 percent of Length of animation "everytime" which means it moves the same distance incrementally overtime(in this case 10 units move in z direction. Thats what this script so far does), BUT rather

moves incementally overtime based on the percentage that is AT everytime it moves.

For example
I want this to first move at (.10 * SULengthofAnimation) but
then move at c.pos.z = (.20 * SULengthofAnimation)-----which would be moves in z direction 20 units
then move at c.pos.z = (.30 * SULengthofAnimation)-----which would be moves in z direction 30
then move at c.pos.z = (.40 * SULengthofAnimation)-----which would be moves in z direction 40
then move at c.pos.z = (.50 * SULengthofAnimation)-----which would be moves in z direction 50
then move at c.pos.z = (.60 * SULengthofAnimation)-----which would be moves in z direction 60
then move at c.pos.z = (.70 * SULengthofAnimation)-----which would be moves in z direction 70
then move at c.pos.z = (.80 * SULengthofAnimation)-----which would be moves in z direction 80
then move at c.pos.z = (.90 * SULengthofAnimation)-----which would be moves in z direction 90
then move at c.pos.z = (1.0 * SULengthofAnimation)-----which would be moves in z direction 100


Now I could do it manually like I am doing here but I want to change the .10 to be like .01(1 percent) or smaller and I cant type that manually becuase it would be to much to do..so I need some kind of routine. Do I need to do a while loop instead of this or what? It should look like the sphere is accelerating over time. Thanks for any help.

-----------------------------------------------

0 Likes
Accepted solutions (1)
411 Views
1 Reply
Reply (1)
Message 2 of 2

Steve_Curley
Mentor
Mentor
Accepted solution
First point is that .1 * SULengthOfAnimation is a constant so regardless of the frames you're setting the keys on the (added) value will always be the same. You need to factor in the Frame number, though the results will get quite big, bigger perhaps than you would need
The 1st key would be 100, the 10th key (frame 100) would be 5,500.

c.pos.z += t * (.1 * SULengthOfAnimation)

Alternatively, leave the frames out of the equation, create a variable which will be incremented (by a smaller value) each time through the loop. Whether you do the incrementing before calculating the value or after will have an impact on the results. If you want the 1st value to be the initial increment, then do the incrementing after calculating the result (c.pos.z).
Remember that if you later decide to set keys on every frame, the amount you add each time would have to be 1/10th of the value you would use if only setting keys on every 10th frame.

This is more a maths question than a MaxScript question - you have to understand what you're trying to do before trying to write code to give the desired result 😉

(
ResetMaxFile #noPrompt
SULengthofAnimation = 100
AnimationRange = Interval 0 SULengthOfAnimation
Increment = 0.1 * SULengthOfAnimation
IncValue = 0.1

c = sphere name: "foo" radius: 5
c.position.controller = Position_XYZ ()

animate on 
   (
   for t = 0 to SULengthofAnimation by (.10 * SULengthofAnimation) do
      (
      at time t
         (
         c.pos.z +=  (Increment * SULengthOfAnimation) 
         Increment += IncValue
         )
      )
   )
)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes