This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Rotate a KinematicBody according to floor slope

randr01drandr01d Posts: 4Member

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

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    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 :smile:

  • randr01drandr01d Posts: 4Member

    Thanks Twisted. I'll be standing by.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Ok, I found the project, but the code was not working :neutral: (and it was poorly written. I guess I've learned a lot since then :smile: )

    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.

  • randr01drandr01d Posts: 4Member

    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.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @randr01d said:
    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 :wink:
    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!

  • randr01drandr01d Posts: 4Member

    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.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @randr01d said:
    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 :smile:

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.