Getting Stuck on Ledges

Posted By: Valdsator

Getting Stuck on Ledges - 10/18/11 22:45

I have a rather annoying problem in my game at the moment. Whenever the player tries to jump on to an unreachable ledge, he gets stuck on the corner of the ledge, slowly moving down until he gets unstuck.

What's basically happening is this:
When the player is not on the ground deceleration is set to 0, so that means when stuck here, the player is constantly moving forward (unless he manually moves back). Because the bounding box of the entity is an ellipsoid, it's automatically trying to climb up the ledge so it can continue moving forward, but gravity is also pulling it down, the force getting stronger each frame. This results in the player falling down very slowly, as the forward movement is resisting gravity, and allows the player to glide sideways on the corner. This could be used to exploit the game, or would simply become really annoying for the player because this happens every time you almost make it on to a ledge.

Anyone have any ideas on how I might be able to fix this? I'm thinking I could prevent it if I set x_move and y_move (c_move uses these variables) whenever the entity gets stuck, but I'm not sure how I could identify that the player is in fact stuck. Perhaps there's a way to make it so z_glide is always more important than x and y glide? Maybe I can magically turn the bounding box in to a cylinder? Wishful thinking. tongue
Posted By: Rackscha

Re: Getting Stuck on Ledges - 10/19/11 08:56

In fact, you can change the Collision type between Ellipsoid(yours) and BBox.
i think BBox is what you need since its quadratic without round shapes.

Its a flag in c_move if i remember correctly. USE_BOX.
Posted By: Valdsator

Re: Getting Stuck on Ledges - 10/19/11 20:47

Hm, didn't change a thing. I think USE_BOX is used for c_trace, which still uses the ellipsoid of the entity, rather than an actual box.
Posted By: Redeemer

Re: Getting Stuck on Ledges - 10/19/11 21:06

Originally Posted By: Rackscha
In fact, you can change the Collision type between Ellipsoid(yours) and BBox.

Nope. wink

Originally Posted By: Rackscha
Its a flag in c_move if i remember correctly. USE_BOX.

That's a c_trace flag that causes c_trace to trace a volume, rather than a line. Ironically the volume it traces is an ellipsoid just like c_move(), not a box.

There used to be a flag for c_move called USE_AABB that caused c_move to use a box instead of an ellipsoid, but it was removed many versions ago because JCL (gamestudio's lead engineer) decided that Gamestudio's collision system was too big.

Gamestudio's implementation of AABB was wimpy anyway; you couldn't adjust the size of the box with min/max but had to be satisfied to use the FAT/NARROW flags, which are really good for nothing. But taking out AABB support was not the right thing to do IMO.
Posted By: Valdsator

Re: Getting Stuck on Ledges - 10/20/11 00:31

I tried checking the vec_length of the vector (x_move * time_step, y_move * time_step, 0), because this should equal the distance variable the c_move returns as long as nothing is in the way. I could use this to identify when the player was in the air, and stuck/gliding on something. This didn't really work (just moving around would set it off), so still looking for a way to fix this.
Posted By: bart_the_13th

Re: Getting Stuck on Ledges - 10/20/11 02:47

You can use the old trick invisible-collision-cube.
Change your model to a cube, set it visible to false, c_move it using POLYGON enabled, then put another dummy entity that represent your actual model at the cube position.
Posted By: Redeemer

Re: Getting Stuck on Ledges - 10/20/11 20:18

That would work great, except ellipsoids are ALWAYS used for entity vs. world interactions. The POLYGON flag only affects entity vs. entity interactions.
Posted By: Valdsator

Re: Getting Stuck on Ledges - 10/20/11 20:52

Originally Posted By: Redeemer
That would work great, except ellipsoids are ALWAYS used for entity vs. world interactions. The POLYGON flag only affects entity vs. entity interactions.
Yeah, I've already tried this (my actual model is just a cube, since it's an FPS), but all entity vs. level collisions are ellipsoid based. I don't think there's a way to get around that, so I need to find a way to prevent the playing getting stuck, or simply fix the problem quickly whenever it happens. Maybe anyone has any ideas on how I might be able to detect if the player is stuck like this? The player has a c_trace under him checking if he's on the ground, if that changes anything, so when he's stuck gravity is still trying to pull him down, and the game knows he's in the air. Obviously, if the c_trace hits the ledge, then the player will be able to walk up on to it, which is how it should work.
Posted By: Redeemer

Re: Getting Stuck on Ledges - 10/20/11 21:35

If you use the USE_BOX flag in your c_trace call then an ellipsoid volume will be traced from the player down to the ground, so even if the player is mostly standing off of a ledge he won't fall. Trace far enough that the ground will be detected even from the far horizontal edges of the ellipsoid and write some code that will keep the player's feet on the ground when the trace returns a hit from a distance.
Posted By: Valdsator

Re: Getting Stuck on Ledges - 10/21/11 03:39

Well, by using USE_BOX I was able to make it harder to get stuck, but it still happens every time you jump on to a ledge diagonally. Any ideas?
Posted By: bart_the_13th

Re: Getting Stuck on Ledges - 10/23/11 00:06

Originally Posted By: Valdsator
Originally Posted By: Redeemer
That would work great, except ellipsoids are ALWAYS used for entity vs. world interactions. The POLYGON flag only affects entity vs. entity interactions.
Yeah, I've already tried this (my actual model is just a cube, since it's an FPS), but all entity vs. level collisions are ellipsoid based. I don't think there's a way to get around that, so I need to find a way to prevent the playing getting stuck, or simply fix the problem quickly whenever it happens.

ah, yes, it seems the engine force it to be ellipsoid.
Ok, how about level vs level collision? Build a simple level consist of a cube, and use that as the entity?
Posted By: Superku

Re: Getting Stuck on Ledges - 10/23/11 00:41

Quote:
Ok, how about level vs level collision? Build a simple level consist of a cube, and use that as the entity?

No matter what you do, c_move is based on c_trace with USE_BOX and that uses ellipsoid ("me") vs. polygonal (all other objects+blocks) detection.

@Valdsator: When c_move hits something (HIT_TARGET), check where target is located. If (target.z < ent.z && target.z > ent.z+ent.min_z), then you will need to move your entity in the direction (f.i.) of the vector pointing from target to ent.z, that is

vec_diff(temp,ent.z,target);
temp.z = 0; // disable vertical movement
var ent_size = vec_length(vector(maxv(ent.max_x,-ent.min_x),maxv(ent.max_y,-ent.min_y),0));
vec_normalize(temp,ent_size-vec_length(temp)); // should be correct, give it a try
c_move(ent,nullvector,temp,...);
Posted By: Valdsator

Re: Getting Stuck on Ledges - 10/23/11 03:20

I just rewrote the vertical movement system which works fine now. Basically I used USE_BOX, and made the c_trace start from the middle of the entity, and have it's z size be as much as the entity. This way, the 2 ellipsoids (the bounding box, and the c_trace) would basically make a rectangular box on the bottom.



Blue = Bounding Box
Red = c_trace

It's obviously a bit more complex than that (some bugs showed up), but I took care of it all. The only problem I have with this method is that if the player jumps, he can climb up ledges which are a tad high, but all that does is get rid of the need for a crouch jump, which I'm willing to sacrifice. tongue

Thanks for all the help!
© 2024 lite-C Forums