When I was studying your request I was wondering how you would be able to apply force on the local x axis when that force is calculated from the object’s speed (and velocity vector). Are we talking about falling objects here?

Basically we are talking about object that is moving arbitrarily.

I want two things:

The unit vector of the movement, so that I can use this vector to apply a force (which would be in the opposite direction)

The speed of the object, which would be the resulting linear velocity derived from the velocity vector. I would then use that value to apply a force to simulate drag. The combination of a force in the opposite direction of the velocity vector, and the same force in the direction of the forward direction of the object will simulate drag and change of direction. When you point the object away from its velocity vector the speed will slow down and the direction of the velocity vector will be changed by the resulting force, until the velocity vector and the orientation of the object line up, and the forces are cancelled out, and the speed is constant.

I am trying to figure out the code myself, and when I do I will post it here

I know I would be something like:

object.getLinearVelocity -> unitvector, speed
force = speed*k (k is an arbitrary constant)
object.applyForce((force*-1*unitvector), false) #false for global
object.applyForce((force*1,0,0), true) #true for local

I am not sure at the moment how to handle the result from getLinearVelocity.

What this script basically does is to produce drag when the object is not coincident with the velocity vector. So in a sense it is a way of rotating the velocity vector, but with reduction of its magnitud.

Is there any way of rotating a velocity vector without reducing the speed? The rotation would be defined by the direction of the object, when it is not coincident with the velocity vector.

I think I misunderstood what you were trying to do. But I noticed that multiplying -vel with speed is slowing it down. If you would just applyForce(-vel, False).

I am not sure what this is supposed demonstrate? Did you try it in Blender? First of all the gravity is positive so you fall upwards, and then no keyes on the keyboard nor mouse respond. Could you give a short instruction what to do, and what result to expect?

How do you rotate a velocity vector without changing its magnitude?

The idea would be that the orientation of the object, when not coincident with the velocity vector, would make the velocity vector slowly line up with the orientation. (slowly = not instantaneously, but according to settings)

@Raco, I did not understand your code, nor did it work in Blender, but I am not sure if I set it up ok, please read above.

You rotate a vector by multiplying it by the correct 3x3 rotation matrix. Check out the methods for
Matrix.Rotation(…). That creates a matrix that will rotate your vector and leave the length the same.

I’m sorry about the confusion. I just have an Always Sensor attached to a Python Controller, with Script Type set to Module: “Test.main”. I tried to find out what you were trying to achieve, but I’m still not sure about it. I posted it just for the purpose of testing. But maybe that wasn’t really necessary. Here’s the blend just to be sure. I hope I wasn’t wasting your time with this. I’m sure the info kastoria wrote will be more useful to you.

[/TABLE]
Aligns any of the game object’s axis along the given vector.
Parameters:

vect (3d vector.) - a vector to align the axis.

axis (integer.) - The axis you want to align
[LIST]

0: X axis

1: Y axis

2: Z axis (default)

factor (float) - Only rotate a feaction of the distance to the target vector (0.0 - 1.0)
[/LIST]

[TABLE=“width: 100%”]

getAxisVect(vect)

[/TABLE]
Returns the axis vector rotates by the objects worldspace orientation. This is the equivalent if multiplying the vector by the orientation matrix.
Parameters:

vect (3d vector.) - a vector to align the axis.

Returns: 3d vector.The vector in relation to the objects rotation.