Gravity - Slopes vs. Falling

Started by
1 comment, last by DCooley 10 years, 4 months ago

Hi there! I was wondering how to determine whether an object is falling or just going down a slope. Here's what I mean: if my character walks off a ledge, I want to slow down their lateral movement speed and make them fall through the air. If they're going down a slope , I want to keep their movement speed fast, just with their position lowered to match the stage's floor. I also don't want the player to slide down slopes unless they're too steep (say, greater than 60 degrees from being horizontal).

I already have character-to-stage collision implemented, and I tried one algorithm to handle gravity already. What I did was cast a ray from the bottom of the character's feet into the floor to find the nearest point on the floor below the character, then created a right triangle. Point 1 was at the character's position last frame, point 2 at the floor below on the current frame, and the right angle straight above the point 2. I then determined if the angle at point 1 was greater than 60 degrees, and made them fall if it was.

This worked at high framerates, but at low framerates the character would ignore high ledges, thinking it went down a slope when didn't, because the character would go so far away from the ledge in one frame that the angle would turn out to be something like 45 degrees, and the character would zip straight to the floor. So that algorithm kind of goes out the window, seeing as it doesn't work if your computer's slow.

tl;dr, How can I discern whether my character is falling off a ledge or walking down a slope?

Advertisement


What I did was cast a ray from the bottom of the character's feet into the floor to find the nearest point on the floor below the character, then created a right triangle. Point 1 was at the character's position last frame, point 2 at the floor below on the current frame, and the right angle straight above the point 2. I then determined if the angle at point 1 was greater than 60 degrees, and made them fall if it was.

That is a method I would have suggested. If you compute an angle of 45° at a small step although it is 60° or more, I assume you are using a collision volume that is not suitable for the given task. It is 2D with pixel masking or the like? I suggest you to either use vector based ground collision volumes or slope annotations. See this article for examples of what I meant. Otherwise you may describe in more detail of what you're doing.


What I did was cast a ray from the bottom of the character's feet into the floor to find the nearest point on the floor below the character, then created a right triangle. Point 1 was at the character's position last frame, point 2 at the floor below on the current frame, and the right angle straight above the point 2. I then determined if the angle at point 1 was greater than 60 degrees, and made them fall if it was.

That is a method I would have suggested. If you compute an angle of 45° at a small step although it is 60° or more, I assume you are using a collision volume that is not suitable for the given task. It is 2D with pixel masking or the like? I suggest you to either use vector based ground collision volumes or slope annotations. See this article for examples of what I meant. Otherwise you may describe in more detail of what you're doing.

I guess I should have specified that this is in 3D, so the stage is a triangle-based collision volume, while the player is an axis-aligned ellipsoid.

I asked this question on another forum and it turns out my problem is with how I was handling time passage and the physics simulation. I was using variable delta time, which apparently can cause pseudo-random simulation to some extent, based on the framerate. I want simulation to be very rigid and repeatable, since I hope to make the game networked and also implement a replay system that saves player inputs and allows a game to be played back. So basically, if re-implement my delta time algorithm, this slope algorithm should actually work.

Nonetheless, thanks for your reply. I appreciate it. :)

This topic is closed to new replies.

Advertisement