How to get speed of object?

I have one question:

If you know, please write as much lines of Python as it’s needed, anyway this question is related to Python.

How to get speed of the object? For example, i have object, called “Something” and i want to make property called “Speed” the same as Something’s speed. Please write such line of script, if you know, of course.

Thanks for that people who will answer me.

this is from memory, it is likely to have bugs

import GameLogic
import math
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
linv = obj.getLinearVelocity()
obj.speed = math.sqrt(liv[0]*linv[0]+linv[1]*linv[1]+linv[2]*linv[2])

thanks for you.

It can seem funny, anyway for these people, who program Python. That’s below:

Could you also write, for example, line of script, making force of object (for example) ten??? I try and try but i haven’t discovered yet why doesn’t this line work as it has to work:

owner.setForce(10, 10, 10 bool local=TRUE)

Could you show my mistake?

Sorry for mistakes i made, but i’m not from England (i’m from Poland)

%|

and next question, this script you showed me, is it getting speed Y or speed X or speed Z, or X speed + Y speed + Z Speed???
:slight_smile:

Hi, i’m just trying your script with is working well with velocity forces.
I’m working on camera mouvment with ipo. I just convert ipo to force to
see the speed value. But it’s not working well.
So, is there a possibity to get velocity value with only ipo curves, or getting speed value with mouvement and object position !! ???

Well, it will not be possible to make camera actor & dynamic

i dont think it should have bool local=true but if it needs a boolean just right TRUE.
(please correct me if i am wrong)

Here is how to get the Velocity (Updated):

import GameLogic as gl
con = gl.getCurrentController()
own = con.getOwner()
speed = own.getVelocity()
speedx = speed[0]
speedy = speed[1]
speedz = speed[2]

if speedx < 0:
	speedx = speedx * -1

if speedy < 0:
	speedy = speedy * -1

if speedz < 0:
	speedz = speedz * -1

speedall = speedx + speedy + speedz

own.speed = speedall #Put whichever speed variable you want here

z3r0 d>


import GameLogic
import math
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
linv = obj.getLinearVelocity()
obj.speed = math.sqrt(<b>liv</b>[0]*linv[0]+linv[1]*linv[1]+linv[2]*linv[2]) 
 
#Typo I believe

It’s supposed to be “linv”, right?

Chaser>


import GameLogic as gl
con = gl.getCurrentController() 
own = <b>gl</b>.getOwner()                 #Typo?
speed = own.getVelocity()
 
speedx = speed[0]
speedy = speed[1]
speedz = speed[2]
speedall = speedx + speedy + speedz
 
own.Speed = #Put whichever speed you want here.

I think it should be “con.getOwner()”, right?

it’s “linv” yes
and “con” fort the second :wink: