I’m making a game with weapons and flipping the gun Is a problem. The player moves using WASD but they rotate based on the mouse position using this:
var animatedtexture:Sprite2D = $animatedtexture
var equipped_weapon:PackedScene
if get_global_mouse_position().x < global_position.x:
animatedtexture.flip_h = false
equipped_weapon.flip_v = true
else:
animatedtexture.flip_h = true
equipped_weapon.flip_v = false
equipped_weapon.look_at(get_global_mouse_position())
This rotate the gun based on the position correctly, but the problem is the offset.
The player is 23x23 pixels and the gun is 26x15 pixels, this may seem normal but the problem is I want the handle to be on the players face. Without doing anything the gun center would be on the players center. So adding an offset. So using the same if checks we set the local position x of the gun to 5 or -5. It looks fine except when changing direction the player can see that the gun position changed which doesn’t look smooth. So does anyone have an idea?
Is a video if anyone wants to see