Tweened object has false global_position

50 Views Asked by At

I'm creating a player tracker that stays behind the player by a few seconds. I intend on having an enemy follow this tracker since I don't want it charging straight at the player. I figured the best way to have the tracker follow the player was with a tween, and I would then just take the global_position of the tracker and use that for enemy movement.

The tracker itself is visually behaving as expected, staying a few seconds behind the player, however it's global_position is exactly the same as the player's. This basically makes it useless since the enemy is essentially directly following the player. I have no idea why it's returning an incorrect value, or how to get the tracker's actual position.

This is the relevant code to my problem. The last line might be causing some issues, but not this issue in particular.

var PlayerTrackerTween = create_tween()
PlayerTrackerTween.tween_property($"../PlayerTracker", "global_position", Target.global_position, 3)
print("Tracker position : "+str($"../PlayerTracker".global_position))
print("Player position : "+str(Target.global_position))
    
var vecToTarget = $"../PlayerTracker".global_position - global_position


vecToTarget = vecToTarget.normalized()
var TargetAngle = atan2(vecToTarget.y, vecToTarget.x)
global_rotation = lerp(global_rotation, TargetAngle, delta * TurnRate)

I'm very new to Godot (literally learned about tweens today), so I have no clue where to begin on troubleshooting this. Any help would be greatly appreciated, thanks.

0

There are 0 best solutions below