[Closed] Constant speed vs constant intervals
Hello all,
I’m trying to do the following : I have a camera animated at constant intervals (one key every 100 frames). So the distance varies between the keys but the interval remains 100 frames.
Now I want to inverse the thing : I want a constant speed between the keys, meaning i must change the durations between keys.
(
clearListener()
desiredSpeed = 1.0
camCtrl =$cam_free.position.controller
targetCtrl = $cam_free.target.position.controller
camKeys = camCtrl.keys
targetKeys = targetCtrl.keys
for i = 2 to camKeys.count do
(
-- The distance between keys
d = distance camKeys[i].value camKeys[i-1].value
-- The time between keys
t = camKeys[i].time - camKeys[i-1].time
-- The speed between keys
s = d/t
-- the ratio between the actual speed and the desired speed
coeff = (s / desiredSpeed)
-- the new time of the key
newTime =((camKeys[i-1].time + t * coeff) as integer) / 160
-- then the offset between actual time and new time for the moveKey command
offset = (newTime - camKeys[i].time)
moveKey camCtrl i offset
moveKey targetCtrl i offset
)
)
The problem is that it seems to scramble keys so that the order of keys is not respected. I don’t see where the problem is. Note : even with sortKeys(), the problem persists.
Any idea ?
try replacing the moveKey commands with something like this:
camKeys[i].time = newTime
or you could iterate backwards like this:
for i = camKeys.count to 2 by -1 do
another thing that can get useful when dealing with time values is that you can get it’s value without dividing by the ticks per frame.
for example if you have:
myTime = 10f
then myTime.frame will return 10.0
I found the problem came from there :
newTime =((camKeys[i-1].time + t * coeff) as integer) / 160
Since CamKeys[i-1].time changed (the key was moved in the previous iteration of the loop), the data was obsolete, making the interval between i and i-1 false.