Linear Velocity Problem

I am currently writing a script to move a character around a map:

import GameLogic
cont = GameLogic.getCurrentController()
owner = cont.owner
mmove = cont.getActuator('Mousemove')
keys = cont.getSensor('Keys')
keylist = keys.getCurrentlyPressedKeys()
if keys.isPositive():
	for i in keylist:
		if i == [97,1]:
			m = mmove.getLinearVelocity()
		if i == [100,1]:
			m = mmove.getLinearVelocity()
		if i == [119,1]:
			m = mmove.getLinearVelocity()
		if i == [115,1]:
			m = mmove.getLinearVelocity()

And I have run into a bit of a problem. I want my character to completely stop moving once the key(s) are released, as opposed to what is happening now, with the character sliding along as though he is on ice. Thanks for the help!

You need an else statement which sets the Linear Velocity to .0001. For some reason LV likes to think setting it to 0 mean apply no force at all, so you need to tell it to set the minimal force possible. setting to .0001 doesn’t apply enough force to actually move the object, but is still able to satisfy the actuator. Hope that helps :P!

if i == [97,1]:
	m = mmove.getLinearVelocity()

#Repeat for all keys, should work :)

Ok two more questions,

  1. I’ve also noticed that if my character goes off the ground, say if there was a cliff in the game that he jumped off or something, he doesn’t fall like a normal object would. It just slides down, at a constant, very slow, rate. Any suggestions?
  2. Is linear velocity the best way to get character to move? I know that if I use DLoc, my character will force his way though solid objects, and if I use force, your fix you gave me for linear velocity doesn’t apply.

I am currently working on the same problem, focused on first person movement…

Since the game engine behaves as it behaves, linV is really the better choice. The collision is ugly and in fact unusable with dLoc. I also needed a “gravityaccelerator” (linV downwards) to make it fall down more quickly.

You may have a look on the prototype shown in the attachment. The Damp Value of 0.99 is important, it prevents the character from sliding down on slopes. It slides only very very small way on common movement until it stops, a thing you can neglect. Currently only forward and backward movement work and setting the direction via mousemovement (you don’t need to go into first person view to test it) Maybe it helps you :s


template mit linV.blend (243 KB)

I like what you did with the raycasting to determine whether or not the object is on the ground, personally if I were you I would set up an empty object near the base of the cube, parent it to the cube, then as opposed to using a seperate sensor for the ray just call a command like this: collisioncheck = owner.rayCast(oblist[‘OBGroundVec’],owner,0,"",0,0)