Rotate a KinematicBody according to floor slope
Hello all, long time lurker of this board, and since version 3 has been out for a while, I'm trying jumping back into Godot seriously now.
I've been building a 3D platformer, similar to sonic in that there should be smooth movement up ramps and such. Also like sonic I want the character (I'm using a KinematicBody) to rotate according to the slope of the current floor, whatever the angle.
I'm using a RayCast, as _IsOnFloor _and _TestMove _are currently bugged for C#.
The RayCast is pointing downwards, so I am able to get the floor normal with the Ray's GetCollisionNormal method (although I see some odd values there when I move around on a flat surface) and I tried getting the angle from that normal, using LookAt with that as the normal, etc etc.
Checking online, I haven't seen anyone fully pulling this off in Godot. Have any of you successfully done so?
Thanks in advance.
Answers
I think I have a project, a failed sphereical gravity platformer, that angles the character based on a raycast normal. Currently I’m away from the PC that has the project, but once I can I’ll see if I can find the code
Thanks Twisted. I'll be standing by.
Ok, I found the project, but the code was not working
(and it was poorly written. I guess I've learned a lot since then
)
However! With some elbow crease, I have been able to rework most of the project to work with angled surfaces (sadly it still does not work with spheres). I just need to do a few more things, clean up the code, and then it will be ready.
Haha, I didn't mean to drag you into any heavy coding work, but I appreciate it! Hope you're having more fun with it than I've been.
No worries, you did not drag me into heavy coding work. I dragged myself in
It was fun to work on and it was nice to restructure my code. It was a little harder than I expected, but since I had the previous code to use as a base it was not too bad.
I have sent you a PM with the project.
For anyone else who has this (or a similar) issue in the future, I plan on writing a tutorial explaining how this all works once I get spherical gravity working. I am currently in the process of setting up my own tutorial website (and Patreon), and it's getting really close to being ready! Once everything is up and ready, I'll write the tutorial there!
Until then, feel free to PM me if you have a similar issue and want the project!
Boom! Worked. You're awesome Twisted. I'll be looking out for your tutorials. If they cover the same material, they'll be light-years ahead of the current godot tutorials out there.
Thanks @randr01d!
I'm super happy the project helped!
As for the tutorials, I will do my best to make them as high quality and useful as possible!
I'll let you guys know when I've got everything up and running