Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Randomize array movement (problem with my script)
  RSS 2.0 ATOM  

Randomize array movement (problem with my script)
Rate this thread
 
64162
 
Permlink of this thread  
avatar
  • kainevan
  • Posted: 04 February 2012 11:53 AM
  • Total Posts: 4
  • Joined: 04 February 2012 11:44 AM

Hi, Im very new to maxscript so please forgive my lack of knowledge..

I have an array of selected objects, They already have keyframe data,
I am attempting to add noise on top of the keyframe data..

For example, i am trying to add some jittering to the X,Y,Z position of the objects..
but it cant over-write the keyframe data already on the timeline. it must be extra movement.

I can’t use a noise-controller it has to be maxscript.

heres what i have so far…
---------------------------

starttime = 0
endtime = 200

for j in starttime to endtime do
(
at time j
(
with animate on
(
move $ [(random 0 10), (random 0 10), (random 0 10)]

)

-------------------------
Running this script works, the position of the blocks are moved randomly and doesn’t mess with my keyframe data that is already there..

The problem is that the whole selection of objects move in exactly the same way..
I need the random movement to be applied uniquely to each object.
Basically a random seed so each objects random movement is different from the others.

Hope I made myself clear.

Thankyou in advance for any help, I’ll highly appreciate it.

Kainevan



Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

Because “$” is a shorthand for the entire current selection - you need a double (nested) loop.

local startTime 0endTime 200

with animate on
   
(
   for 
theFrame startTime to endTime do
      (
      
at time theFrame
         
(
         for 
obj in selection do
            
move obj [(random 0 10), (random 0 10), (random 0 10)]
         
)
      )
   )

Tip. Always wrap any code you post inside CODE tags - the forum display can mess with code making it impossible to copy/paste from the post correctly.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar
  • kainevan
  • Posted: 05 February 2012 02:38 AM

Thanks for the help! (and the tip)
This is probably a seriously easy fix but i tried your code with my objects selected and it finds an error…

-- Error occurred in anonymous codeblock; filename: ; position: 16; line: 1
-- Compile error: no local declarations at top level:  starttime
-- In line: local startTime =

Its obviously not liking something about local.. Could you possibly help me on this one too?
Im very very new to maxscript so even the simplest fix seems like a war to me,

Cheers, K

local startTime 0endTime 200

with animate on
   
(
   for 
theFrame startTime to endTime do
      (
      
at time theFrame
         
(
         for 
obj in selection do
            
move obj [(random 0 10), (random 0 10), (random 0 10)]
         
)
      )
   )


Replies: 0
avatar
  • kainevan
  • Posted: 05 February 2012 02:43 AM

My apologies, I don’t know exactly what i’ve done by deleting “Local” but i just had a play around with the script (Literally i just testing deleting parts to see if it was a minor problem)

Low and behold this worked for me…

startTime 0
endTime 
200

with animate on
   
(
   for 
theFrame startTime to endTime do
      (
      
at time theFrame
         
(
         for 
obj in selection do
            
move obj [(random 0 01), (random 0 01), (random 0 01)]
         
)
      )
   )

Sorted! Thankyou very much, If you have the time, Fancy shedding some light on what the local thing did? and what i’ve done by deleting it?

Regards, K



Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

I know exactly what it is. I wasn’t aware that your code was the entire script so I posted it “as is”.

Rather than remove the local, place the entire script within parentheses.

(
--the entire script above goes here, including the local
)

As a matter of principle scripts should be contained within parentheses to prevent their variables being created in the “global” scope, which could easily affect any other script which happend to use the same variable names.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0