Compass issue thing (i might just be dumb)

Godot Version

4.3

Question

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.

Replace your skull_pos etc to skull.position


Make sure to paste scripts instead of screenshots

1 Like

nope didnt work still the same problem

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
  • will look at the arm if it is 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.

2 Likes

Thank you gentlemen i stand now corrected that i am just dumb. (nvm)

Eh, these things come with (sometimes bitter) experience. We’ve all screwed up that way. It’s how you learn.

well it looks like this now:

extends Sprite2D

@onready var arm: Node2D = $"../../../../../collectible_1"
@onready var eyeball: Node2D = $"../../../../../collectible_2"
@onready var skull: Node2D = $"../../../../../collectible_3"


func _process(delta):
	if arm.visible:
		if eyeball.visible:
			if skull.visible:
				look_at(skull.global_position)
			else:
				look_at(eyeball.global_position)
		else:
			look_at(arm.global_position)

same problem

That’s still not going to do anything if arm isn’t visible.

1 Like

it is though everything is visible
im trying to have it where it points at one then when the player collects it it switches to the next one

I feel like you probably want something like:

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")
1 Like

idk i give up its just not working i tried

look_at(skull.global_position)

and that alone doesent work

If you print(skull.global_position) and maybe global_position for your sprite as well, what do you get?

it just prints the x, y cords for the node

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

nope this node is very alone

Ok, but what actual values are you getting for skull.global_position and global_position?

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.

wdym stomp something in?

rotation = PI

That ought to display the sprite upside-down, since there are 2*PI radians in a circle. If it doesn’t, something is stopping the sprite from rotating.