How do I fix my turret targetting?

I’m trying to get my turret to stay locked onto the enemy that is closest to its base (or the vat sprite)

It should pick the slime that is closest to its base and shoot at it indefinitely

But right now if a new slime enters its range it will shoot at that before the closer one is dead and it will never retarget the old one


Also, any ideas for fixing the turret spinning out of control when a slime gets too close?

Why do you link each TurretBase with a random TurretHead (there’s no condition that selects the TurretHead)?

Why are you waiting 1/2 a second before aiming and firing? The closest RedSlime could change in that time. And remembering that the events are processed about 60 times per second, those events will be processed and queued up for actioning about 30 times before the first waited event starts up. All you’re achieving with the wait action is delaying the targeting and firing at RedSlimes by a half second. Is this really what you’re after?

Also, I think the action that picks the closest RedSlime only does so for the parent event actions. It may not be doing it for the subevents. For that, use a “pick closest” condition.


I’d suggest:

  1. Removing the linking of TurretBase and TurretHead in the Turret Function grouped events.
  2. Removing the pick closest RedSlime action
  3. Add a pick closest RedSlime to the conditions of the “Repeat for each instance of TurretBase” event.
3 Likes

Thanks, the turret properly picks the closest object now. Also, I originally wanted to wait 0.5 seconds to make sure that the bullet didn’t fire at the direction the turret was originally facing. Right now, I decreased it but there’s like a few frames where the turrethead isn’t flipped so the bullet shoots as if it were coming out of the base.

That should be fixed with the update to the repeat event’s conditions.

Also, why do you link the laserProjectile to the RedSlime? I can’t see a reason for it if laser hits the slime, the slime should take damage. It’ll look strange if a laser passes through one slime and damages one behind it. Additionally, I believe the laserProjectile it uses might not be the most recent one that gets fired.

I linked the projectile to the slime because I thought that maybe at a longer distance when the bullet missed and ended up hitting a different slime it would target that one, but now with the implementation of this fix I guess it’s not really necessary. Anyways, I got rid of it.