object.getLinearVelocity, outputting positive values in any direction?

Hi all,

I apologise if I am saturating the forum with questions, feel free to move/delete if needed.

Back to my question: I have an object that uses object.getLinearVelocity to get its speed. Now, logically, it outputs a +ve reading in the +x, +y and +z directions, but when travelling say, backwards (i.e. -x), or to the left (-y) or down (-z) I get negative numbers.

How do I get around this? I know the output is logical but how can I make it so that it reads positive answers whatever direction I go in?



simply use the abs() funktion.
abs(-10) # returns 10

If You want the total speed just do object.worldLinearVelocity.magnitude (2.5x - in 2.49 I think You have to convert getLinearVelocity() to a Vector first).

Excellent, sevi! Everything is working!

LaH, how would I fit world linear velocity into this? I have tried a direct swap with linear velocity but I get errors:

import GameLogic

controller = GameLogic.getCurrentController()
object = controller.owner

Xspeed, Yspeed, Zspeed = object.getLinearVelocity(False)

linSum = Xspeed 

xValue = linSum

object['speed'] = abs (xValue)

kph = object['text2']

object['text'] = str(int(xValue)) + str(kph)



It seams like You only want the speed along the x axis - then abs() make most sens.