0 votes

So, I am planning to make slopes in my game(because mountain regions in story and that when I was messing around I found out a cool sling shot way for cool platforming puzzle ideas) But I want the sprite to rotate at the angle that is relative to the angle of the ground collision. I'm thinking to add in a code saying that "if the player is grounded and the angle of the collided object is not 0, then rotate to relative rotation" of some sort. I'm not sure how to execute in the "rotate to relative rotation" part though. :/ The player body is a RigidBody2D, not a kinematic body.

in Engine by (83 points)
edited by

2 Answers

+1 vote
Best answer

For rigid bodies, you can check the state in _integrate_forces, there you have access to get_contact_local_normal.

But may be better by just using a RayCast2D pointing down and only rotate the visual part, not the whole body if not needed (easier to manipulate).

by (7,896 points)
selected by

Okay thanks!

0 votes

If your "player" is a KinematicBody2D (and "grounded" = "collided with the ground") then you can use the get _ collision _ normal() function, which returns the normal of the ground (below the character).
This normal (Vector2) is perpendicular to your slope, so you can calculate it's angle (ie. with the Vector2's angle_to(Vector2 to) function).

by (674 points)

Ooo but I have A rigid body character because I was lazy to put in gravity >.< I forgot to say that, sorry.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.