0 votes

What I'm trying to do is change transform.basis.z according to ground normal:

Image 1

As you can see in a flat ground the transform.basis.z is (0,0,1)

Now in a angled ground as you can see:

Image 2

I need to set the transform.basis.z to the approximate following value: (0, -0.534175, 0.845374). Well you obviously would answer me saying: just call transform.basis.z right? Well I can do that because this rotation you are seeing is inside the editor I rotated the rigidbody for taking screenshots only, also the transform.basis.z I'm using is another node :

enter image description here

Godot version 3.2.4 RC1
in Engine by (100 points)

1 Answer

0 votes

I had the same problem. link

I copied what someone did on Unity answers. Godot doesn't have the Quaternion.LookRotation method so I used look_at towards the normal plus an offset by the forward direction so it keeps it's orientation.

var raycast_point = raycast.get_collision_point() + raycast.get_collision_normal()
var player_direction = global_transform.basis.xform(Vector3.FORWARD)
look_at(raycast_point + player_direction, Vector3.UP)
rotation_degrees.x += 45
by (3,225 points)

this way of solving the problem requires that player scale Vector3(1,1,1), because its similar to one I found on KidsCanCode site! That one is limited to this scale!

How do you mean? Scale doesn't have anything to do with this because it's a case of looking from point A to point B.

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 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.