RandyGaul / player2d

Educational demo implementing a swept 2D character controller
89 stars 10 forks source link

NGS Could Cause undesired behaviour #9

Closed SetLinux closed 4 years ago

SetLinux commented 4 years ago

due to the way NGS works when on a slope and continuously jumping for example after a bit of time you can realize there is some movement in the X axis because you are everytime pushing the player by a small amount in the normal of the collision and that would add up causing movement in some extreme cases

RandyGaul commented 4 years ago

You’re absolutely right! I’m actually going to be using this demo for Handmade Seattle. It’s a convention for low level “hand crafted” software. My plans are to add in explicit code paths for dashing, slopes, standing on crates, and one way platforms. I’ll be presenting next month.

In the case of slopes my preferred strategy would be to detect when the player is on a slope, disable gravity, and use specific code to move the player up and down the slope. This way any custom behavior can be achieved. My plans are to let the player intersect the slope so the players center along the x axis is visually standing on the tiles.

Does that make sense?

SetLinux commented 4 years ago

thanks for the fast response , actually this is perfect , i did something similar to the x axis penetration in unity and it worked great (used the shape cast stuff from rigid body iirc) but i think this still suffers from one problem that is sloped roofs you still would get pushed out with the normal of the sloped roof

SetLinux commented 4 years ago

for example here : Peek 2019-10-20 17-37 this isn't sliding i am applying just an upwards velocity

SetLinux commented 4 years ago

any advice you can give ?

RandyGaul commented 4 years ago

When on slopes, disable gravity, and use an explicit code path to move along the slope. This is like a different state if the player is considered a state machine. Then, when they jump or otherwise leave the slope, enter back into the normal walking state.

RandyGaul commented 4 years ago

Just closing this out. Feel free to comment here or reopen it if you like :)