[Closed] rotate by radius
hey gang,
i found an old script to autorotate the ball when traslate it… and if you change the radius… it update the rotation…
i remember it worked like… 5 years ago… but i’m trying to use now and max report error in line:
v: T:0
anyone can help me?
thank you very much
this the entire script:
obj = $Sphere01 – change this
timeres = 1f – time resolution
fn getrot t =
(
if t<=0f then return quat 0 0 0 1 – we assume at t=0 obj is aligned with the world
t0 = t-timeres – previous frame time
t1 = t – current time
rot0 = getrot(t0) – get the rotation in the previous frame recursively
p0 = at time t0 obj.position – previous position
p1 = at time t1 obj.position – current position
if(p0==p1) then return rot0 – if no distance is traveled, rotation is the same as previous frame
dif = p1-p0 – difference in positions
len = Length(dif) – distance that’s traveled
vec = dif / len – normalized movement vector.
r0 = at time t0 obj.radius – previous radius
r1 = at time t1 obj.radius – current radius
rotax = cross vec [0, 0, 1] – rotation axis
angle = 360*len/((r0+r1)*pi) – rotation amount (in degrees)
rotdif = quat angle rotax – Quaternion which defines rotation from t0 to t1
rot1 = rot0 + rotdif – final rotation
)
getrot(currentTime)
v: T:0
v: S:0
v: F:0
v: NT:0