Set linear velocity of an object on one axis of the motion actuator via Python

I want to set a linear velocity of a dynamic object. But whenever I try to do it as in a single axis, it won’t work via Python - it is just zero speed, even though the object is dynamic.

Example of a code which should normally move anything provided there is a Motion actuator named “movement”:

import bge
import bge.logic as gl

cont = gl.getCurrentController()
own = cont.owner

movement = cont.actuators['movement']

movement.linV[0] = 3.0 # This doesn't even move the object at all for some reason

cont.activate(movement)

But if you run the sample code, it will not do any kind of movement, but printing out the linear velocity in the console shows the speed of the object, however it seems to be at nothing.

I really want to set an object so it goes along a single axis at a constant speed rather than using a tuple through the motion actuator’s linear velocity python. I even tried it using the location, still no luck. Why is it doing that?

I’m curious, any reason why you aren’t setting the linear velocity directly via python? You can do it like so:

def setLinearVelocity(cont):
    own = cont.owner
    localVelo = own.localLinearVelocity # This is a mathutils Vector object
    localVelo.x = 4
    localVelo.y = 0
    localVelo.z = -3 # Can set any individual axis
    print(f"total velocity: {localVelo.magnitude}") # or get the magnitude

    # Can get linear velocity in the world axis as well
    worldVelo = own.worldLinearVelocity

    # Should print the same number
    print(f"total velocity from world velo: {worldVelo.magnitude}") 

Usually, I find local linear velocity the most useful, and I use it in a lot of movement scripts since it’s based on the object’s direction