#Need help identifying offset on weapon spawn

1 messages · Page 1 of 1 (latest)

edgy sorrel
#

Hello! I need help identifying the cause for the discrepancy between these two pictures. On the left is how my weapons spawn in-game, and on the right is the spawn positions in the editor. I have the weapons roughly where I want them through trial and error, but I'd still like to learn what exactly is going on here.

Here is the relevant code.

`extends CharacterBody2D

var weapons = 0

#Dorbs
var basic_dorb = preload("res://Player/Weapon/basic_dorb.tscn")
var shotgun_dorb = preload("res://Player/Weapon/shotgun_dorb.tscn")
var rifle_dorb = preload("res://Player/Weapon/rifle_dorb.tscn")

#Dorb spawn points
@onready var dorb1 = get_node("%Orb1")
@onready var dorb2 = get_node("%Orb2")
@onready var dorb3 = get_node("%Orb3")
@onready var dorb4 = get_node("%Orb4")

func add_dorb(dorb):
if weapons < 4:
var new_dorb = dorb.instantiate()
dorb_equipped.append(new_dorb)
match weapons:
0:
new_dorb.global_position = dorb1.position
dorb1.add_child(new_dorb)
1:
new_dorb.global_position = dorb2.position
dorb2.add_child(new_dorb)
2:
new_dorb.global_position = dorb3.position
dorb3.add_child(new_dorb)
3:
new_dorb.global_position = dorb4.position
dorb4.add_child(new_dorb)
weapons += 1
else:
pass`

#

Some things I have already checked for in the editor. My orb nodes are marker2D, and they are children of my Player CharacterBody2D with a position of 0, 0. All of my weapons have a position of 0, 0. When I set the position of an orb node to 0,0 it correctly instantiates the weapon between the feet of my character. My Player Sprite2D is scaled to .5 on x and y, but if I set it to 1 all the positions are still offset. I'm struggling to think of any other variables in play that could be causing this.

Like I said, I more or less have my objects spawning where I would like by accounting for the offset, but I'd like to understand why this is happening in case it causes issues down the line. Any ideas or thoughts would be greatly appreciated.

#

Figured it out pretty much as soon as I hit send. Sometimes you just have to write it all out I guess. 🥲

Adding each dorb as a child of the markers already sets their position appropriately. I was in effect adding the global position of each marker twice.