Get object velocity

Hi, im pretty new to python for BGE and i was wondering how I can record an objects local ‘y’ velocity and record it to a float property.
I have this so far but it does’nt work, so im guessing its probably completely wrong:eyebrowlift2:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

def main():

# get forward velocity
lin_speed = obj.linV


own.get(“Velocity”) = lin_speed
This is attached to a python comtroller attached to a cube, which has a very simple movement system. The cube has a property called “Velocity” which I want to store the cube’s current velocity.


This is a code i recently got helped with. It works very well.

import GameLogic

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

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

linSum = Xspeed + Yspeed + Zspeed

xValue = linSum

print (linSum)


Great, thanks, but i cant get it to work, does it need any specific logic setup?
Edit: Nevermind, solved it now.

How do I get the local velocity instead of the global and write it into a property?

Local I dont know. sry. but like this you get it into a property

object['PropertyName'] = xValue

Ah, thanks. This is why I cant be a programmer, i always think the solution is going to be more complicated, then it all just goes wrong :stuck_out_tongue:

For local, I think you can replace the ‘False’ in the script above with a ‘True’ to get the local velocity.

Excelent, that works , thanks.