# Detect object speed?

I have some objects that I need to know how fast they are going. I have a property, "speed," and I would like it to show the object's speed in blender units. For the unit, it doesn't matter that much as long as I can read it. Python or logic would work, but if it's a script I'll have it running at all times. In other words, I'll be using this every logic tic so it needs to be efficient. Thanks.

EDIT: I've figured out how to find velocity on my own, but how would I use that xyz info to find speed?

• every second or every logic tick? – Scalia May 5 '15 at 23:48
• I want the property to display speed every tick. – blackhole May 6 '15 at 0:32
• speed or velocity, not a physicist but I think their slightly different. – Scalia May 6 '15 at 3:28
• @Vince Scalia Probably velocity, although I don't see a difference. – blackhole May 6 '15 at 12:48
• Does this solve it: blender.stackexchange.com/questions/29007/… ? You can call it with scene_update handler instead of frame_change – Jaroslav Jerryno Novotny May 15 '15 at 6:27

Keep track of the objects previous position. Algorithm:

on each logic tick:
speed_vector = current_position - previous_position
speed = speed_vector.length()
previous_position = current_position


I have found a nice script from here, and it is the following:

# get the controller
controller = GameLogic.getCurrentController()

# get the game object that the controller is attached to.
obj = controller.owner

# get local (game object) linear velocity
linVelocity = obj.getLinearVelocity(True)


I have modified it for my own scene, and I've also defined speed.