Notifications
Clear all

[Closed] Efficient object speed retrieval

I was wondering what the most efficient way to check an object’s speed at a particular time is. Since there is no magic attribute to grab an object’s speed, I’m looking for a very efficient way of doing this check… If I want to retrieve the speed in units/sec at a particular time period, I suppose I could get currenttime, then use at time one frame previous and compare it to currenttime, but this seems a little hacky.

Is this the best way to do it? Just a little question Not sure if it deserves its own post, but I figured this would be a useful topic to some people.

I would prefer to be able to grab an object’s speed as a vector, similar to what you can retrieve with a scripted pflow operator, say if you spawn particles from an animated object, then read the speed values of the particle, you retrieve a vector. I could immitate this by grabbing the two time positions then subtracting their point3 positions, but it still seems like a workaround to what should seemingly be built in…

3 Replies

Your approach is correct.
You should understand that while an object has position animation, the speed at any given time is a result of that position animation, while in the case of the particles in PFlow, the speed is a PROPERTY that results in the position animation:

Object: Position -> Speed
Particle: Speed -> Position

Particle Flow INTEGRATES particles at a given interval using the last known position and the current speed to calculate the next position.
Scene Objects have all their positions determined by either keyframes or procedural controllers and in order to get the speed, you have to sample two or more positions.

If you get the speed in an interval of 1 frame, you will have to multiply the result by the FrameRate variable to get the value per second.

The MAXScript Reference contains a simple example of a script that creates a text file with speed info from scene objects. See “How To … Output Object Data To File”.

For an extended example (albeit very old), see
http://www.scriptspot.com/bobo/mxs3/speedometer/speedometer020.ms

Cheers,
Bobo

awesome, thanks Bobo

Hi!, I was trying to make a script related to this subject, it’s was supposed to make a custom attribute on any object, called velocity, with an scripted controller inside, that samples positions of this object in time, and claculate velocity.
Here is the code:

PhysicsData = attributes "physics"
   (
   	parameters main rollout:velocity
   	(
   		vel type:#float ui:velspinner 
   	)
   	rollout velocity "Physics Data"
   	(
   		spinner velspinner "velocity" type:#float
   	)
   )
   
   CustAttributes.add $ PhysicsData
   scr = float_script()
   scr.addNode "obj" $
   scr.script = "p1 = at time (currenttime - 0.5f) obj.pos
 p2 = at time (currenttime + 0.5f) obj.pos
 distance p1 p2"
   $.vel.controller = scr

I got some problems:
after applying the script to the object, everything seems to work, but when I slide the playhead, something happens with the script controller, and I tryed to figure out what it is, but until now, I don’t know what’s the problem,

I would apreciate very much if someone can copy/paste the code, select an animated object, and run the script.

thanks!