#Rotation of Anchor node breaks when player moves.

14 messages · Page 1 of 1 (latest)

bold goblet
#

I have an object under my player called anchor that looks at the mouse and sets the scale of the object to -0.4 if the mouses x position is less than the x position of the anchor, however when the player moves from 0,0 the rotation gets screwed up and starts moving on its own? help greatly appreciated.

#

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()

mental mauve
#

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.

bold goblet
mental mauve
#

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.

bold goblet
#

still having the same issue, its getting offsetted for some reason when the character moves, still works fine at 0,0 though

mental mauve
#

What does the rotation handling code look like now?

bold goblet
#
    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)

mental mauve
#

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)

bold goblet
#

IT WORKS (for the most part but this seems pretty easily fixable) thanks a bunch!