Why isn't my item looking at my mouse position after pickup?

Godot Version

Godot 4.2.2

Question

My item spawns to my hand node that is the child of pivot node in the player scene. Anything inside $pivot.look_at(get_global_mouse_position())
works and looks at mouse pos but my item stays still.

This is the item script body entered signal.

@onready var hand = get_node(“/root/Testworld/player/pivot/hand”)

func _on_player_entered(body):
reparent.call_deferred(body.find_child(“Weapons”), false)
position = hand.position
body.add_item(stats, skill)
collision.set_deferred(“disabled”, false)

I assumed because the item goes to the hand.position it should’ve worked. Any ideas?

There is probably a rotation property in addition to the position.

But the “transform” would have both.

I would set the one transform equal to the other.

There might be global and local transforms, I cant remember. But one should do the jobe for you.

1 Like

Still stuck lol Is it just rotation to the mouse position or do I use the look at?

My apologies still new to programming.

extends Sprite2D

@onready var collision = $Area2D/CollisionShape2D

@onready var hand = get_node(“/root/Testworld/player/pivot/hand”)
@onready var pivot = get_node(“/root/Testworld/player/pivot”)

@export var stats : Item
@export var skill : Skill

func _ready():
if stats != null:
texture = stats.icon

func _on_player_entered(body):
reparent.call_deferred(body.find_child(“Weapons”), false)
position = hand.position
rotation = pivot.get_global_mouse_position()
body.add_item(stats, skill)
collision.set_deferred(“disabled”, false)

This coincidence simply subsided. As one gradually repaired. It’s merely a minor disturbance. You have to reparent the item back to the scene tree.

It’s nothing serious. But, it will no longer listen to the contents of the Main script. And, it will no longer take referee from calls that are contained inside it’s own script. For example in cases like player position.

If I enter look_at in the item script in the process function.

func _process(delta):
look_at(get_global_mouse_position())

All the items look at the mouse position and even when I pick up an item. But if I put it in _on_player_entered(body) function same script.

func _on_player_entered(body):
reparent.call_deferred(body.find_child(“Weapons”), false)
position = hand.position
look_at.get_global_mouse_position()
body.add_item(stats, skill)
collision.set_deferred(“disabled”, false)

The Item spawns frozen looking at the mouse position.

_process is called every frame, when is _on_player_entered being called?

when the player(body) enters the area2D node and sends a body entered signal.

My question would be, is it being called at all?

Place a print statement the line before or after the line in question, for both versions of your code.

Run it and check the output in the console.

Is the non-working one being called only once or not at all? The working one should be called once per frame and have many printed lines.

1 Like

set_deferred refers to using a tactic to prevent repeated simulation. for example during the same frame when an object collides with the same entity. tolling the FPS. gradually crashing. call_deferred probably references the next frame in the simulation.
there is a certain drawback for using set_deferred, like from delta. but, the documentation design places the set_deferred as;

var node = Node2D.new()
add_child(node)

node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5

await get_tree().process_frame
print(node.rotation) # Prints 3.0

for creating an uninterrupted node with rotation. I think in your case it’s holding your mouse position update after the first frame.

1 Like

That makes sense whys it doesn’t rotate. Thank you

1 Like

I figured it out another way by adding a second animatedsprite with the items inside just like the FX and now everything is working as it should. Now i’m trying to drop the item back to the world.

1 Like

I’m still trying this out because its bothering me lol and using set_deferred the player doesn’t pick up the item.

i’m just trying to help according to the garage information. the documentation refers to shuffling between

func _physics_process(delta):
	pass
func _process(delta):
	pass

Because the internal error for the engine would state;
Function "_process" has the same name as a previously declared function.
You can see this error if you add _process(delta):
Again. Essentially this is what will happen to your item. While it’s on the outer field as it’s moved to set_deffered. Because that’s a different zone.

1 Like

Sorry about that should’ve made a vid lol is there a way? Maybe a bool.