2D character movement like Limbo

I need help with 2d character movement. I want the character to be able to walk along slopes without sticking (friction), and not to stick to 90 degree vertical slopes.

This is my current script:


import bge
from bge import logic
from bge import events
cont = logic.getCurrentController()
own = cont.owner
x_linv = own.getLinearVelocity()[0]
z_linv = own.getLinearVelocity()[2]

if logic.keyboard.events[events.AKEY] == 2:
    x_linv = -7.5
if logic.keyboard.events[events.DKEY] == 2:
    x_linv = 7.5
if cont.sensors["g"].positive and logic.keyboard.events[events.SPACEKEY] == 1:
    z_linv = 10

own.setLinearVelocity([x_linv, 0.0, z_linv], 1)

Can someone perhaps edit it for it to work, or is there a better script?

Thanks

is a dynamic object?

i think you can use a sensor ray to align the char with ground

It’s a dynamic object, but aligning the character isn’t the only problem: The character can stick to walls, but I want friction for movement.

mhh…

to get the limit of 90 degrees , you can using the vector Z of your char
when this is < 0 (both to the left and to the right) mean which the slope is more than 90° degrees

vecZ=own.worldOrientation[2][2]

if vecZ<0:
…falls

PS: really the vector Z is own.worldOrientation[2] …but you need to the second item of the vector…:wink:

I’ve never played Limbo, nor can I preview its movement style at School, however if you were to more specifically outline what you want the movement mechanic to be like i’m sure I could help.

I basically want the movement to be like in this video:
Limbo Gameplay Part 1/7
You don’t slide everywhere, you don’t take long to fall back to the ground, and you can’t stand on steep slopes, but you can on gentle slopes.

What I usually do is lower the friction to 0 for the materials so that the player doesn’t stick to walls, and then program friction myself. Something like:



movespd = 0.1
maxmovespd = 2

if kleft:
     obj['mx'] -= movespd
elif kright:
     obj['mx'] += movespd
else:
     obj['mx'] *= obj['friction']

obj['mx'] = min(max(-maxmovespd, obj['mx'] ), maxmovespd) # Limit movement to maximum move speed

obj.setLinearVelocity([obj['mx'], 0, obj['mz']])


Combine that with the inability to move or stop in the air, and you’d have something to work with.