4
$\begingroup$

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?

$\endgroup$
7
  • 1
    $\begingroup$ every second or every logic tick? $\endgroup$
    – ruckus
    Commented May 5, 2015 at 23:48
  • $\begingroup$ I want the property to display speed every tick. $\endgroup$
    – blackhole
    Commented May 6, 2015 at 0:32
  • $\begingroup$ speed or velocity, not a physicist but I think their slightly different. $\endgroup$
    – ruckus
    Commented May 6, 2015 at 3:28
  • $\begingroup$ @Vince Scalia Probably velocity, although I don't see a difference. $\endgroup$
    – blackhole
    Commented May 6, 2015 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$ Commented May 15, 2015 at 6:27

2 Answers 2

5
+25
$\begingroup$

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
$\endgroup$
0
2
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .