I'm making a 2D top-down game. I'm adding these turtles that wander around autonomously.
The 1st turtle was working fine (using AnimationTree). Why would creating a 2nd or 3rd instance of my Turtle Scene cause the 1st turtle to animate improperly? AND, when I deleted the first turtle and added a new one, it didn't work at all? It's like somehow my code was referencing that exact turtle and when I deleted it it just stopped working.
Why would the AnimationTree be tied to 1 specific turtle? Any ideas?
More detail:
Ok, so I created a Turtle Scene. It has an AnimationPlayer, an AnimationTree and a Node2D with some code to make it wander around. I have animations for IdleLeft, IdleRight, IdleUp, IdleDown, WalkLeft... etc. I set them all on the AnimationTree with using AnimationNodeBlendSpace2D.
I used this same scheme to animate my player and it works perfectly. I repeated the technique with the turtle (which is automated, does not require player input) and it WORKED! (but then it stopped working when I added more instances of the Turtle)
The idea is that every few seconds the turtle would wander to a random point. I pass a movement vector into the AnimationTree's blend position and it walks to the point.
func accelerate_towards_point(point, delta):
print("walking")
moveVector = global_position.direction_to(point).normalized()
animationTree.set("parameters/Walk/blend_position", moveVector)
animationState.travel("Walk")
velocity = velocity.move_toward(moveVector * MAX_SPEED, ACCELERATION * delta)
func stop_moving(delta):
animationTree.set("parameters/Idle/blend_position", moveVector)
if velocity != Vector2.ZERO:
print('stopping')
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
print(velocity)
else:
animationState.travel("Idle")
BUT THEN I added a second and third turtle thinking I could just drag the Turtle scene into the world and see the walk behavior work exactly the same for multiple turtles.
When the 2nd and 3rd turtle wandered, the FIRST one would spaz out and have its animation change rapidly. As though the 1st turtle was trying to do all of the animations for all of the turtles, and the other turtles just drifted around without animating.
Currently any turtles I add drift around without animating, but I know I'm not crazy. I saw my turtle working perfectly before I deleted him and added a new one.
Anyway, pretty stumped right now as I don't see how my code could be referencing a specific instance. I'm also new to Godot but I'm a long time programmer so I have a good grasp on code fundamentals. Any help appreciated!