i dont know if im being really dumb or something but i cant seem to making a god damn compass. every time i load the scene it will point to the node but not update so it just sticks pointing in one directio. please help!
position is of type Vector2, this isn’t derived from Object so it’s value is copied when you assign it. The skull/arm/eyeball are of Node2D type which does inherit from Object, so they will be referenced, not copied, any update to the node including it’s position will be visible.
May need to use skull.global_position for look_at depending on how the scene tree is set up. Make sure to paste code changes as you make them, I don’t know what you wrote.
Your if/elif chain seems strange, how do you intend for it to track these? Currently it will
only look at the skull if all three are visible
only look at the eyeball if arm & eyball are visible
Is it not rotating at all? If so, you might also want to stick in an else to see if your code is skipping all the logic. Maybe something like:
if arm.visible:
if eyeball.visible:
if skull.visible:
look_at(skull)
else:
look_at(eyeball)
else:
look_at(arm)
else:
print("oops")
My bet: arm isn’t visible so it’s skipping all the logic. With the code as you currently have it, if arm isn’t visible then it will fail all your active branches.
var target = null
# Increasing order of priority:
if arm.visible:
target = arm
if eyeball.visible:
target = eyeball
if skull.visible:
target = skull
if target:
look_at(target)
else:
print("Nothing to look at")
Also, might there be any other code interfering with the rotation of your sprite? If something else is reaching in, it could be stomping anything you do with look_at().
For that matter, if you stomp something into rotation, does the sprite rotate? Like, if you do rotation = PI / 3?`
look_at() just takes a vec2, so you can also potentially see if the problem is the coords you’re handing it, or if it seems like look_at() is the problem. You could do something like:
look_at(Vector2(0, 1000))
which ought to make the sprite turn ~90 degrees clockwise.