Replace applyMovement with applyForce?

Hi all,

I’m currently using Blender for some quick prototyping on my games design degree. I haven’t really delved into the python side of things before but it looks pretty straightforward.

I’m using the mouselook system that can be found here:

Quite simply the system uses applyMovement to give the camera the movement. I would like to use applyForce (it suits my purposes better) but switching ‘applyMovement’ with ‘applyForce’ doesn’t work though from what I see it should.

If anyone has any pointers it would be greatly appreciated :slight_smile:

Are you sure you want to use apply force? You will be sliding all over the place.

Anyway, you have to make the gameObject that your referencing a physics object. Specifically “dynamic” or above.

Thanks for the reply!

Yeah I’m pretty sure I want to use force - the game is third-person and underwater so the sudden start and stop feels unnatural.

I have made the gameObject dynamic in the logic panel if that’s what you mean. If it needs to be specifically referenced in the python how do I do this?

Also here is the snippet of code that I’m trying to change:

# These two are different, because the motion
# they are applying is global.
if rise:
    own.applyMovement([0.0, 0.0, SPEED], 0)

if sink:
    own.applyMovement([0.0, 0.0, -SPEED], 0)

movement = [X, Y, Z]
own.applyMovement(movement, 1)


That’s all you have to do.

The word “own” was already made a reference to the gameObject, otherwise applyMovement would not even work.

That’s what I thought but I’m not having any success? I’m getting no movement - is it possible there’s a conflict somewhere?


if you are going to be using force and velocity it may be useful to know things such as limiting velocity and dampening speed (to stop sliding)

# Limiting Velocity
from Mathutils import Vector

velocity = Vector(object.getLinearVelocity())

if velocity.magnitude > limit:
    velocity = (velocity / velocity.magnitude) * limit

object.setLinearVelocity(velocity, 0)
# Dampening Velocity
from Mathutils import Vector

velocity = Vector(object.getLinearVelocity())

if (you want the object to stop but not instantly):
    velocity = velocity / 1.1

object.setLinearVelocity(velocity, 0)

You would place these examples after you have applied your force.

As for your problem you need to set the camera to be dynamic in the logic panel. If you have it as dynamic it will be effected by gravity. One it is dynamic the applyForce will work for it.