While making a new fps engine one issue has stood out. sliding down slopes.
I know it sounds weird, but you know how fps games (or any first person one for that matter) allow you to go up slopes without any speed decrease up until a certain angle (like 40 degrees) and then after that a speed decrease and sliding will be applied until below that angle. This sounds reasonable, as you can also stop on said slopes without sliding down. This could be used both indoors and out.
Q: indoors? how so?
A: indoors as in stairs.
Q: but stairs are flat.
A: in games, stairs have clips to make them smooth.
Q: so stairs are slopes?
A: Yes. If you play CS 1.6 on any map (dust 2 for example) and slowly go up the stairs, you will jolt up each step. In CS:GO, everything is clipped so this doesn’t happen. A video by 3kliksphilip explains how the engine deals with stairs. (found here) it perfectly explains how source deals with stairs.
Ok. question time.
Is it possible to have a physics object go up a slope without consequence, only until 40 degrees, with only then having an effect, with stopping on the slope possible without sliding down? The max cutoff would be 45 degrees. If the imposter is on a 45 degree slope it cannot go up and will slide down until it reaches a 40 degree slope.
Bonus question!
Is it possible to prevent a physics imposter from rotating past 45 degrees? Not much explanation here. If so, cool! if not, I’ll figure out something eventually.
I do not use the physic to move my characters.
I use moveWithCollision () and it climbs the stairs perfectly without the addition of additional ramp. After playing with gravity, the higher it is, the more the character slips on the slopes.
I imagine that with physics, it will also play with gravity when the character is on a slope to lower it dynamically.
How it works: WASD are associated with a side of the cube. w applies a force from the back, a the left side, etc, etc. space applies an impulse if canjump is true, which is hooked up to the spacebar keyup. shift slows you speed to a walk. continually jumping will make you bhop, but if you stand still, jump for a while, and then move. you WILL go VERY fast.
the cube rotates for the slope(~30 degrees) and gravity is turned to like 0.0001 (0 made it so you would sometimes fly). If I can get this going good then I won’t have the gravity at 0.0001 on the slope.
Oh, and one more thing. the gravity is at -70 because the jump was too floaty at a normal gravity.
Thanks for the help! any ideas on the rotation lock?
Awesome work so far, looking super cool! I don’t have any really clear thoughts about the rotation thing just yet; my current thoughts are around adding an onAfterPhysicsObservable, but nothing fully-formed yet. I’ll keep thinking about it, though.
Regarding the sliding thing, what do you think about the possibility of waking and sleeping the Impostor based on the circumstances when you want the thing to move? https://www.babylonjs-playground.com/#IFN77Q#40
This is, of course, a very crude proof-of-concept; it just dumbly wakes up the Impostor when you press a key, then puts it to sleep again when you release the key. Because of this, it’s possible to get stuck in mid-air by pressing the space bar and releasing before you land, and things get all kind of confused when you press two keys at once. But try going up the slope (just W and mouse-look) and see how that feels to you.
If that’s along the lines of what you’re looking for, it should be possible to construct a more sophisticated set of checks and triggers to only make the Impostor go to sleep when you really want it to (i.e., when you’re in contact with the ground and not pressing a key). The most useful tool to pursue this would probably be registerOnPhysicsCollide(), which will give you callbacks for the kinds of collision events that will motivate you to change your Impostor’s state.
Don’t know if any of that will work, but it should be at least interesting/informative to try. Might play around with myself later if I get some time. Again, awesome project so far!
I do remember that post, but it was you who started and continue this work. It’s so cool to see how far you’ve taken it in such a short time! Keep it up!