Switch target on tapping spawned actors
I am creating a game that involves being able to tap on an enemy to constrain it's X,Y to global variables GlobalX and GlobalY, and then a projectile will aim to that X and Y. Global X,Y are set to 0 until the enemy is touched. I've also constrained a "target style" image to the enemy target to visually show which enemy is selected.
The issue is, I can get the first spawned actor to be locked on, but when I tap another instance/spawned actor, it won't switch to the next target. Only the first spawned actor can be targeted.
If it is destroyed, then it will allow me to target the next one but none other. I'm not sure what I'm doing wrong or if this is a known behaviour in GS.
I am using rule:
If touch is released (or inside) (on the enemy ship) then
Constrain GlobalX with Self.Position.X
Constrain GlobalY with Self.Position.Y
Then i have a button which when pressed will shoot a projectile to GlobalX, GlobalY if they are not null - otherwise the button will do nothing.
If I touch another enemy actor with the same rules, I would have expected it to overwrite the constrains but it doesn't even seem to recognise the touch/release.
I'm kind of stumped here and was hoping someone in the community had a good system for tap/targeting that didn't involve instantly shooting at that screen position, but rather more like a "lock on".
Thanks in advance!
Answers
Actually I think what is happening is that the constrain is still happening with the first touched actor... I tested by putting a timer on the constrains and saw the target image jump between all the touched enemies. Gotta try and work out how to break the constrain which an identical spawned actor is pressed... hmm..
Sorted this out... its tap on and tap off but still works well...
Glad you got it sorted!
Developer For BLUNTentertainment - Feel Free To Message Me! - Free Beginner Templates!