Godot Version
v4.2.1.stable.mono.official [b09f793f5]
Question
The tween isn’t working as intended; instead of moving each object 100 units to the left, it sends them all to a single point. In the top script, the positions are correct, and visually they’re in the correct positions. However, in the bottom script, the global positions of the enemies are all the same, even though visually they appear at different locations.
[This script is attached to the map]
var xOffset = 100
func SpawnerE():
if spawner_nodes.get_child(4).get_child(0).get_child_count() < 3:
for i in range(3):
var newObj = BTYPEENEMY.instantiate()
spawner_nodes.get_child(4).get_child(0).add_child(newObj)
var newPosition = Vector2(i * xOffset, 0)
newObj.global_position = spawner_nodes.get_child(4).get_child(0).global_position + newPosition
print_rich("[color=green]Global position from map: [/color]", newObj.global_position)
[This script is attached to the enemy]
func MoveToLeft():
if moving:
return
var currentPosition = global_position
moving = true
var tween = create_tween()
print("Current position from enemy: ", currentPosition)
var targetPosition = currentPosition + Vector2(-100, 0)
print("Target position from enemy: ", targetPosition)
tween.tween_property(self, "global_position", targetPosition, 1)