Slope Physics not working when trying to make Sonic face movement direction
I'm working on a 3D sonic framework in Unity, and I'm starting to implement animations and player rotation. I ran into a bit of a problem where animations are all working as intended which is good, and the rotation works well on flat ground, but it messes up the slope physics completely, and when braking sonic turns at a slight angle for some reason. It should be in the video but it's kinda hard to pick out because I haven't added the braking animations yet. (turning off the rotation script makes everything work normally again so it's definitely the rotation script that's the problem). I've been trying to figure out a solution for a bit now but with no luck, so some help in figuring this out would be greatly appreciated.
Here are the relevant scripts for this:
RotationHandler (attached to capsule): https://pastecode.io/s/rv1418xi
MoveAction: https://pastecode.io/s/8092tzsm
PlayerPhysics: https://pastecode.io/s/p2qb2q81
Player Rotation Handler in Unity (rv1418xi) - PasteCode.io
This C# script for Unity manages the rotation of a player character based on movement input. If the player is braking, the rotation is ignored. Otherwise, it calculates the target rotation from the movement vector and smoothly applies it to the player transform, enhancing the gameplay experience.
18 Replies
i'd advice to read on how sonic slope physics work https://info.sonicretro.org/SPG:Slope_Physics
also i'd advice against rotating the player directly
looking at your code
This is the basis of what I've been working with, but it doesn't translate that well into 3D in some parts. Slope detection works, it's just that I'm trying to implement a rotation script for sonic the face in the direction he's moving like face left when going left etc and that new script is what's messing up the slope physics
yeah
you shouldn't directly rotate the model
you should ideally applying a tangential force based on the angle you are on the ramp
it's a bit tricky
tbh i haven't done this for 3d
i have done this for 2d
i found this roblox thread https://devforum.roblox.com/t/sonic-slope-tilt-momentum/1994364
Developer Forum | Roblox
Sonic Slope Tilt & Momentum
I’ve spent the past few months working on creating a Sonic game with a friend of mine and my movement system is practically complete. It involves multiple stages of speed with increases to WalkSpeed over time and ties into several other systems I’ve completed (Many of which use AlignPosition and do not alter WalkSpeed). The last thing that I was...
maybe you can get ideas from this
ideally you want to emulate SA/2 physics i suppose?
Yeah that's the goal
I even pseudocoded a basic momentum system:
tbh even sonic frontiers doesnt have slope physics because it has boost
think like a high speed car going on a ramp
Yh i think i get what you mean
yeah experiment
but you dont rotate the sonic model when you are upward the slope
This is how things look without the rotation handler script. Rotation handler only handles his y-axis rotation so looking left and right
that what is causing the issue
yeah that is buggy
but i wonder can you reduce the cylinders size?
it's cause of the snap function. It's supposed make it so that uneven ground isn't that much of an issue
this return doesnt look correct
i think you should do something instead
then return
sorry but wdym? This is my first time implementing physics like this i only know the basics
yeah im also not sure about this until i debug in unity
maybe you can try debugging in unity
sadly i dont want to download unity again
ohhh alright i was literally about to say that my current project is public on github and if you wanted you could have a look urself lol
I've tried a bit before but I'll try again
Debug.Log about to work overtime