Making character actually fall on cliffs.

Hello !

I’m facing my stupidest issue yet ^^

Basically my Sonic character is a capsule. While on ground, I cast a ray from the center, in the direction of -transform.up to check for ground. But I only do so when on ground (so that I don’t take off if I run into a slope, or downstairs, things like that).

When I’m in the air, I use a spherecast, so that if I’m falling into a slope, the collider doesn’t “get in the way”, if the slope’s too steep.

And I use snapping to snap where I should be.

Everything works fine except for when getting at a cliff (I mean arrive at the end of a path, so that if you go further, you fall).

Since the ground raycast is fired from the center of the player, if I move just towards the cliff and put more than half of my capsule in the air, it will automatically say “not on ground” => “spherecast” => “thick enough to touch the ground from behind” => snaps player back to hit.point at the center. So basically you get that “back and forth” thing when trying to move forward out of a cliff at low speeds.

Any idea how to fix this ?

EDIT: I just found out something but it feels super weird : I could use a timer to disable my player’s collider for like 0.1 sec when entering !onGround state to have him fall through the ground and then be popped out on the side ? That’s the behavior that seems to be in SA2.

EDIT2: Or maybe I could just move forward by 0.5 * colliderRadius whenever I enter the !onGround state ?

EDIT3: Or put him upwards a with a speed boost …? I don’t know guys

I think you just need to check the angle of the ground. Anything too steep is a cliff.

You probably also need to be doing multiple checks together, rather than just one or another. For this kind of stuff your checks will need to be comprehensive.

Hey sorry for the late reply, I got overwhelmed with life.
Thanks for answering !

So I managed to make something work. When reaching the edge of a surface, the character now is propelled a bit forward and its ray/sphereCasts are disabled for a short period. And it seems to be working really well after many tests.

But I also face another issue I noticed (which was already present prior to this).

When I fall on an edge, weird things happen. (ground normal can have weird values because of the edge, like, even though it’s a cube, I get weird normals pointing with angles on the edge).

How can I make it so that it does something like this gif ? See how he’s pushed away ? Rotating the character make him be pushed the same way (he doesn’t rotate or anything, he’s just “pushed” away from the surface.

9367199--1310018--pushed.gif

Looking at it, it feels like if the capsule collider was sliding off the ground at the same speed regardless of the position on the edge.

Is this something we can do ?

You can do whatever you want. It’s your code. You’re also the only one who can debug these issues.

And like I mentioned, you will likely need to do multiple checks. Character controllers like these are corner cases upon corner cases.

Also, I know folks like to make fan games, but you’re asking to have lawyers knocking on your door.

I’m sorry I didn’t understand that last part ? Layers ? If you meant “Lawyers”, know that the screenshot is actually from a famous fangame itself. Also, Sonic Team is very opened to fan games

That was meant to be lawyers.

Yeah I figured, I don’t see how that would happen though. There are already tons of Sonic fan games out there. Not sure why I would get in trouble. Especially when some crazy enough people tried to make money off their fan game, didn’t have issues

And yet I have friends who have run into legal issues, hence the word of warning.

Nonetheless, this is still up to you to debug what’s going on here.

Legal issues ? More than a cease and desist letter ?
Also FYI :
https://www.nme.com/news/gaming-news/sega-provides-greenlight-for-fan-made-sonic-titles-2941415#:~:text=Sega has officially voiced its,money or include illegal content.

But thanks for the concern though.

As for the programming issue, like I said, the issue’s fixed. But I wonder if we can easily (meaning built in Unity way) tweak the way a capsule collider slides off an edge. Currently, the further away from the edge, the faster it’ll slide away. Is it possible to have a fixed speed for that ?

Colliders are shapes, nothing more. They have no more dynamics beyond that. A Rigidbody moves, an attached Collider is just along for the ride and produces contacts to be solved.

In 3D physics you can hook into these contacts and perform your own actions based upon them.

https://docs.unity3d.com/ScriptReference/Physics.ContactModifyEvent.html
https://medium.com/waveaccess/contacts-modification-api-in-unity-d65deba6f7c

Thanks ! I’ll look into that :slight_smile: