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?

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.