![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | seanc |
Video preview of the bug I’m facing →
I am prototyping some top-down movement and tried implementing movement similar to Battlerite. Player movment with w a s d and rotating the character with the mouse–very traditional top-down movement controls.
The problem I am facing is when I am moving my character around it is rotating the character, even when I am not moving the mouse at all.
You can see in the video preview I provided at the top of this post that the mouse position does not move at all. I did some troubleshooting and somehow calling look_at
while moving the character. If I comment out look_at
there is no more rotating.
So my real question is: Is there a way to stop character rotation while only moving in my implementation? I only want mouse movement to control how much the character rotates.
var drop_plane = Plane(Vector3.UP, player_bottom.global_transform.origin.y)
var ray_length = 1000
var mouse_position = get_viewport().get_mouse_position()
var from = camera.project_ray_origin(mouse_position)
var to = from + camera.project_ray_normal(mouse_position) * ray_length
var distance = Vector3.ZERO
distance.y = player_bottom.transform.origin.distance_to(body.transform.origin)
var intersects_at = drop_plane.intersects_ray(from, to)
var cursor_pos = Vector3()
if intersects_at:
cursor_pos = intersects_at + distance
body.look_at(cursor_pos, Vector3.UP)
body.rotation = body.rotation * Vector3.UP