Blender Game Engine Movement

Hello all,
I am using a motion actuator to control my character’s movement, and I am using the Linear Velocity option, rather than simple motion, just so I can get a bit of a skid when I let go of the joystick. I have a python script setting the linear velocity on the x and y axes to a factor of the joystick’s axis tilt. As the actuator sets the linear velocity for all axes, however, the z axis acts odd when I move in midair. Depending on my settings, I either get the character hovering in midair, or dropping at a constant rate, not speeding up at all while it falls. How can I get the character to fall while moving, and still use linear velocity?
Thanks!

Vel = obj.getLinearVelocity()
if (int(Vel[0]) != 0) or int(Vel[1]) != 0 or int(Vel[2]) != 0:
 if int(Vel[2]) == 0:
  obj.getLinearVelocity().z += obj.getLinearVelocity().z

I’d dos something like this ^ but it’s your call on how you wanna make that handler.

Thanks for the reply Frederick! Sorry, I’m no expert with python. Can you explain in detail what everything here means? Obviously, Vel = object.getLinearVelocity() is creating the variable Vel for the object’s linear velocity. What exactly do the other three lines do?

you should leave the z component unchanged, therefore you can only act on the y or x component

for example, this increases the linearVelocity along the local Y
obj.localLinearVelocity.y += 2.0

1 Like

Thanks for your reply. The script I’m using is shown below. As you can see, I’m trying to set only the x and y velocity values of the actuator, but it still seems to set the z velocity to a constant value when the character moves in midair. I tried doing localLinearVelocity but, using a joystick to control the game, that just makes the movement unresponsive and inaccurate. And I need to set the linear velocity, as far as I know, because I have a joystick controlling how fast the character moves, based on the tilt of the stick (if I have the stick tilted just a little bit, I want it to walk slowly continuously, not gradually speed up to a run).

if abs(left_analog_y) > dead_zone or abs(left_analog_x) > dead_zone:
      cont.activate(moAc)
      moAc.linV.x = -5*left_analog_x
      moAc.linV.y = 5*left_analog_y
        
 if abs(left_analog_x) <= dead_zone and abs(left_analog_y) <= dead_zone:
      cont.deactivate(moAc)

The problem is moAc that sets the z component.
Don’t use it, modulate the velocity yourself as you need with python.
Mine was just an example to show you how to increase the linearVelocity along the local Y.
To ensure that once you reach a certain speed it doesn’t go any further you can use a condition, so for example:

if abs(left_analog_y) > dead_zone:
  acceleration = left_analog_y*2.0
  maxVelY = 5.0
  velY = obj.localLinearVelocity.y
  if velY<maxVelY:
    obj.localLinearVelocity.y += acceleration

*if you need to work in global coordinates use the “worldLinearVelocity”

I was thinking about the answer I gave you, maybe if you prefer to continue using moAc, before calling it you could detect the linear velocity on the z component and then pass it to moAc.
so your code should be:

velZ = obj.worldLinearVelocity.z #detects the linear velocity along global Z
if abs(left_analog_y) > dead_zone or abs(left_analog_x) > dead_zone:
      cont.activate(moAc)
      moAc.linV.x = -5*left_analog_x
      moAc.linV.y = 5*left_analog_y
      moAc.linV.z = velZ

 if abs(left_analog_x) <= dead_zone and abs(left_analog_y) <= dead_zone:
      cont.deactivate(moAc)

I did a simple test and seems to work

I noticed that if you use a motion actuator you have to preset at least one of the linear velocity component (x or y or z) different to 0.0, otherwise the actuator does not activate.
As you can see, i set the z component as -0.1, but this value does not matter, because the script then overwrites it.

Thanks for the tips Lopas! I’ll give it a whirl.