Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

rotation script controller crash
show user profile  cadmonkey33
I'm hoping one of the maxscript gurus here may be able to help me.
I've modified this script by Cuneyt Ozdas to make my wheels rotation dependent on the distance they've travelled since the last frame.
It works great, but I'm getting random crashes while using it. Max just stops responding and I have to close.
This seems genuinely random, it can happen on any frame.

I'm using Max Design 2012 SP2 64bit.
Can anyone see any obvious problems with this script?

obj = $leftrearwheel -- change this
timeres = 1f -- time resolution
fn getrot t =
if t<=0f then return quat 0 0 0 1 -- t=0 => no rotation
t0 = t-timeres -- previous frame time
t1 = t -- current time

rot0 = getrot(t0) -- previous rotation:

p0 = at time t0 obj.position-- previous position
p1 = at time t1 obj.position-- current position
if(p0==p1) then return rot0 -- no distance is traveled

dif = p1-p0 -- difference in positions
len = Length(dif) -- distance that's traveled
vec = [0,1,0] -- single axis rotation

r0 = 33.0 -- fixed radius

rotax = cross vec [1, 0, 0] -- rotation axis
angle = 360*len/(r0*pi)-- rotation amount (in degs)
rotdif = quat angle rotax -- rotation from t0 to t1
rot1 = rot0 + rotdif -- total rotation



Nat Saiger.

read 460 times
10/14/2011 7:29:19 PM (last edit: 10/14/2011 7:29:19 PM)
show user profile  Garp
Not too sure but your recurrence looks strange.

No matter what frame t (> 0) the function currently uses, it always calls itself with the previous frame:
t0 = t - timeres
-- . . .
rot0 = getrot t0

which in turn calls itself with the previous frame, etc, until t == 0.

So for t == 0, getrot 0 returns quat 0 0 0 1.
For t == 1, getrot 1 calls getrot (t - timeres), that is getrot 0, which then returns quat 0 0 0 1.
For t == 2, getrot 2 calls getrot 1, which calls getrot 0, which returns quat 0 0 0 1.

The code never gets past the 4th line - rot0 = getrot t0 - and always returns quat 0 0 0 1.

edit: scrap all that. I should have read better.

Just a question though. Are you using a path constraint?

read 451 times
10/15/2011 12:03:07 AM (last edit: 10/15/2011 11:43:01 AM)
show user profile  cadmonkey33
hi Garp,
the car is on a path constraint yes. wheels are linked to the car.

here is a link to the original script and blog, just in case its helpful.

it was originally to roll a ball, so maybe this is overkill for what im trying to do.
but it does work well apart from the random crash :)

Nat Saiger.

read 422 times
10/15/2011 4:11:29 PM (last edit: 10/15/2011 4:14:15 PM)
show user profile  Garp
Indeed it's much simpler for a wheel. And if it's contrained to a path it's even better.
I have a Jing in the tutorial section that shows one way to do it. It should help :)

As for Cuneyt's script crashing, could it be a memory issue? At each frame, the function calls itself all the way down to the 1st frame. At frame n, getrot() is called n+1 times. So if the animation is long enough it can be a problem. It'd have to be pretty long though (or your system pretty poor in memory).
Or it's something else entirely...

read 417 times
10/15/2011 4:24:18 PM (last edit: 10/15/2011 4:24:18 PM)
show user profile  cadmonkey33
yeah i'll simplify things and use your technique. the only downside would be a small slide when turning corners, but i don't think i'll be close enough to notice that.

interestingly i tried Cuneyt's script in max2011, and it gives a random unhandled exception, but doesn't crash max. i think theres a max bug involved here.

thanks for your help.

Nat Saiger.

read 407 times
10/15/2011 7:16:48 PM (last edit: 10/15/2011 7:16:48 PM)
show user profile  Dub.
from memory, the maxscript stack can only handle about 800 recurses before it crashes.

read 397 times
10/16/2011 12:30:54 PM (last edit: 10/16/2011 12:31:05 PM)
#Maxforums IRC
Open chat window