#Rotation of Anchor node breaks when player moves.
14 messages · Page 1 of 1 (latest)
Rotation Handling:
if mousePos.x < $anchor.position.x:
$anchor.scale.x = -0.4
$anchor.look_at(-mousePos)
else:
$anchor.scale.x = 0.4
$anchor.look_at(mousePos)
mousePos: var mousePos = get_global_mouse_position()
It's because the mouse position is in global position, so -mousePos mirrors it across the origin, not the player. Rather than messing with negative scale, I recommend just setting the sprite's flip_h property to true, and always just look at mousePos
Actually, given how you are turning it, flip_v is more likely the one that you want. But the point is, the sprite flipping properties won't mess with coordinates and cause problems.
I need to scale it since the anchor object is used to rotate the hands and gun sprites that the character has, it also controls the shooting direction also
There's never a need for negative scale, you can always work around it. But if you really want to do it that way, you'll need to have the mouse position in local coordinates so you can manipulate it relative to the player, then wrap it in to_global() before you pass it to look_at()
And given that you are only flipping the x scale, you want to also make sure you only flip the x position of the mouse.
alright, so i tried this and now the mouses position is sort of left behind when the player moves around fixed, i failed to update the cursor sprites position lol
still having the same issue, its getting offsetted for some reason when the character moves, still works fine at 0,0 though
What does the rotation handling code look like now?
if mousePos.x < $anchor.position.x:
#both axis of the globalmousepos need to be flipped, dunno why but it works at 0,0
$anchor.scale.x = -0.4
$anchor.look_at(to_global(-globalMousePos))
else:
$anchor.scale.x = 0.4
$anchor.look_at(globalMousePos)
mousePos: var mousePos = get_local_mouse_position()
globalMousePos: var globalMousePos = to_global(mousePos)
also, by 0,0 i mean the players spawn location (the local 0,0 for the player)
You don't want to do to_global(-globalMousePos), you want to flip the local mouse Pos, then convert that to global; to_global(-mousePos)
IT WORKS (for the most part but this seems pretty easily fixable) thanks a bunch!