I am working on a simple platformer game. I have a cube (dynamic object) as my player character with servo control actuators to move it in each direction when the corresponding key is pressed. How can I keep the player from sliding on the floor after movement? I have tried running a script that sets the object’s linear velocity to 0, 0, 0, when no keys are pressed, but it doesn’t seem to work. I have also fiddled with the friction settings, but when I turn the friction up it slows the player’s movement down.
Any advice would be greatly appreciated.
Here’s the file. I’m running UPBGE 0.3 alpha.cb_test_stage.blend (886.8 KB)
chances are your script is only running when you are pressing a button.
try adding ‘always’ and connecting it to the script
import bge own = bge.logic.getCurrentController().owner cont = bge.logic.getCurrentController(). if cont.sensors['Right'].positive: if own.localLinearVelocity.x<5: own.localLinearVelocity.x+=.1 elif cont.sensors['Left'].positive: if own.localLinearVelocity.x>-5: own.localLinearVelocity.x-=.1 else: #friction is here own.localLinearVelocity.x*=.9
Thank you so much! That script works great.
I also added movement on the y axis. The only problem is that when I move the player around it hops up when I move diagonally. I assume I should program the vertical directions separately.
Not vertical, diagonal. My bad.
so - sometimes popping in the air is from crossing boundary between meshes or triangles
I tend to fake friction and have actors ‘Ride’ on a ray / sensor pad
ne_ware_actor.blend (895.3 KB)