hi all i need help with something
i got this code somewhere on some forum , don't remember where
but i love it , works wonderfully on a rotation script controller
i need to do the same thing only on a single axis to auto turn a wheel
and im failing at converting it to work for my needs
any an all help would be greatly appreciated
here is the code
obj = $ -- 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 = 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 degs)
rotdif = quat angle rotax -- rotation from t0 to t1
rot1 = rot0 + rotdif -- total rotation
)
getrot(currentTime)