Notifications
Clear all

[Closed] Speedometer Play Animation Issue

Hi

  I have just made a Speedometer to check the speed of my objects in mph.
  I works fine when you scrub the time line and play animation with realtime turned off, but as Soon as I turn the realtime back on I get an odd result. I end up with a irregular speed, with it sometimes going up to 10 mph faster or slower than it should be displaying.
  
  Im using a timeCallback to call my function. The function then gets the position of the object, and the position of the object at the frame before. I then used "distance" to get how far its traveled.

 I wondered if it could be the code below that is giving me the issue, is it not able to work this out fast enough, and therefore comparing a distance greater than 1 frame? 

I’m using it to give me the frame before the current one. so I can get the object position

at time (((currentTime as integer)/TicksPerFrame) - 1) (targetBefore = target.pos)
 Has anybody had issues like this before?

Thanks

Phil
8 Replies
 lo1

First of all, you don’t really need the whole ((currentTime as integer)/TicksPerFrame) – 1) expression. (currentTime – 1) works just as well.

About your question, please post the rest of your function

Oh ok yeah, I wasnt sure I could use that as “currentTime” was in frames and not an standard integer. I should have tried it though thanks.

in fact that alone has fixed it. It now displays the correct speed thanks. Not really sure why I over complicated it.

 lo1

Your code is working fine for me.

Thanks, with the (currentTime – 1), its great.

			target = pPickedNode
 			targetBefore
 			frameSeconds = (1 / framerate as float)
 			--format "
___frameSeconds_%
" frameSeconds
 			at time (currentTime - 1)
 			(
 				targetBefore = target.pos -- get the position of the object in the previous frame
 			)
 			disMM = distance targetBefore target.pos 
 lo1

Strange, there should be no difference between the two

Yeah it does seam strange as the previous version worked when scrubbed or played not in realtime.
But I don’t really understand the line ((currentTime as integer)/TicksPerFrame) anyway.
currentTime = 912f (for example)
(currentTime as integer) = 175104 Why is this the value how does it arrive here???
TicksPerFrame = 192 because its a 24fps file
((currentTime as integer)/TicksPerFrame) = 912

I need to read into this a bit more so I understand exactly what it is doing. I found the line in the maxscript help when trying to find out how to convert the 912f to a integer.

 lo1

currentTime as integer is the current time expressed in ticks. Since it’s 192 ticks per frame, this number is 912 * 192.

If you want just the frame integer, you can use currentTime.frame, but that isn’t necessary as the at time context accepts a time interval value, not necessarily an integer value.

That makes sense I didn’t realize “currenttime” as integer give me the time in ticks, and now that I understand that, the oddity still doesn’t make sense. but it doesn’t matter to much, as I have a working solution. Thanks for taking the time to explain that to me.