Topic was automatically imported from the old Question2Answer platform.
Asked By
nonunknown
What I’m trying to do is change transform.basis.z according to ground normal:
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:
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 :
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
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!
nonunknown | 2021-02-15 19:35
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.