pitch control with Linear Velocity screws gravity


For my game I use a sound script that multiplies the speed with the pitch of a sound.

cont = GameLogic.getCurrentController()
act = cont.actuators["slam"]
obj = cont.owner

linVelocity = obj.getLinearVelocity(True)[0]
if linVelocity < 0:
	linVelocity = linVelocity * -1

obj['speed'] = linVelocity * 0.15 + 1

obj['sound'] = act.pitch
act.pitch = 0.7 * obj['speed']

The problem is the that linear velocity screws up the gravity when you use rigid body (which i need).

My question is. How do you get a pitch control on my sound without screwing up gravity?
If you use Dloc the LinV is 0 and will stay 0 if i move. Also problem with Dloc is that it works like a teleports and thats works rather bad with walls (it looks like you drive into a wall and you get pushed out).

You’re using local velocity. That screwing up velocity because the X axis, which you’re setting the speed to, can change. Just use global velocity instead.

But than my tank would get a speed on the global X axis and that’s not the way i’m driving in. so this does not work either.

I tried without the whole script thing to get is working and found out that when you ADD the velocity, the z axis velocity isn’t 0 (so it doesn’t messes up the gravity) when you move because you don’t set linV z to 0.

I’ll have a try (tomorrow) to get this working and report back. (i need to make a script that adds velocity until i reach a maximum speed but that ain’t difficult i think)