|
|
|
 |
Reply From: |
Markus Dick |
I know this is kinda late, but since i was strugeling with the same problem and found no real answers online i thought i comment here:
The problem is that move _ and _ slide moves the kinematic body in the global transform, while the rotation is stored in its local transform.
Lets say your direction Vector is (through key presses for example):
var global_direction = Vector3(0,0,1)
and you don´t want to move in the global direction, but in the local direction the kinematic body is facing. First, you rotate the vector on the axis you want (in my example i rotate around the y-axis ( its the Vector3(0,1,0) )):
var local_direction = global_direction.rotated(Vector3(0,1,0), rotation.y)
rotation is a Vector3 that stores the current rotation of the kinematic body in radians and since i want to rotate around the y-axis i use its y value
Finally you can call move _ and _ slide(), in my example however i want to apply speed to the direction first:
var velocity = local_direction * SPEED
move_and_slide(velocity)
I hope this helps people, that want to achieve some first or third person movement and use a kinematic body as a player and move with the move _ and _ slide() method.
Oh boy. Thank you so much for this… I was tearing my hair out! I think I’ll make a PR to update the docs to mention that move_and_slide is not expecting local coordinates like Translate
does…
Matthew Goulart | 2020-04-19 19:15
Finally, after spending hours scratching my head and looking for help everywhere without getting any. Thenks.
I must say, I laughed at myself for not thinking about something like that.
magicalogic | 2020-11-15 18:25