unclear documentation on applyImpulse()

I am making my first game in the BGE, it is about hovercar “races” i am trying to get my cars to go forward at the moment and after reading the api docs i figured out a good choice for this purpose would be using applyImpulse()

however, i am not quite getting what coordinate system it uses

here is how i think works:


(x and y axis are local to the object with zeroes at the object’s origin)

and here is my code stripped to its bare minimum


def thruster( control ): #control is a list of 4 boolean values representing forward, back, left and right, respectively

    thrust = 0.1
    turn = 0.25
    
    impulsePoint = mathutils.Vector((0,-1,0))
    impulseDirection = mathutils.Vector((0,1,0))
    
    if control[2]:
        impulsePoint.x += turn
        
    if control[3]:
        impulsePoint.x -= turn
    
    if control[0]:
        obj.applyImpulse(impulsePoint,impulseDirection * thrust, 1)
    
    return

This code does not quite do what i expect.

instead, it seems like the impulse direction and point might be global on global coordinates, with just the point being offset by the object’s position.

here are my results :

http://i.imgur.com/41z4q4g.gif

EDIT: in the GIF you can see that the cube moves along three different roughly linear paths, instead of taking a turn.

any help will be appreciated. thank in advance!

point = object.worldPosition+ object.worldOrientation*Vector([x,y,z])

thrust = object.worldOrientation*Vector([x,y,z])

localize the point and thrust vector

Mind showing me what my function should look like? I still cant get it to work

EDIT: Nevermind i just got it. Thank you!

import bge
from mathutils import Vector
cont =bge.logic.getCurrentController()
own= cont.owner
Thruster = own.children['Thruster'].worldPosition
DirList =[  ['Up',[1,0,0]], ['Left',[0,1,0]],['Down',[-1,0,0]], ['Right',[0,-1,0]]  ]
Vect =Vector([0,0,0])
for control in DirList:
    if cont.sensors[control[0]].positive:
        Vect = (Vect+Vector([control[1]))/2
    
    
force = own.worldOrientation*Vect
own.applyImpulse(Thruster,Vect)

this assumes the sensors for the arrow keys are named ‘Up’, ‘Left’,‘Down’, ‘Right’

and all sensors are connected to this script

a child object named ‘Thruster’ is where the impulse is applied

I would recommend using applyTorque() to steer instead of applyImpulse but both are fun to play with :smiley:

edit: no problem have fun!!!