Need a little help with targeting system / pick nearest ...

Get help using Construct 2

Post » Fri Oct 17, 2014 10:47 pm

I was implementing a targeting system in my game, but I've got stuck when finding the next target.

About my code:
Local static number "targetMode" is the type of targeting the player is using as it follows:
[1] When activated, targets the closest enemy at that moment. When that enemy is destroyed or offscreen, the targeting mode is disabled.
[2] When activated, targets the closest enemy at that moment. When that enemy is destroyed or offscreen, targets the next closest enemy.
[3] When activated, continuously targets only the closest enemy.

Function "toggleLockOn" activates and stops the targeting system.
Function "setTarget" should target the closest enemy at that moment.
Function "releaseTarget" stops the targeting system.
Function "targetIntro" is the nice effect when the target appears onscreen.

The issue is that after I destroy an enemy that is targeted, the target remains in the same place, so I think the problem is in the function "setTarget" witch picks the same object even if the object should be destroyed.
You do not have the required permissions to view the files attached to this post.
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Fri Oct 17, 2014 11:17 pm

You are picking by target.targetID (events 16,21,27) but if that target is destroyed, there is nothing to pick so the "destroyed" logic is never being called. You need to shift that to trigger either on the enemy collision, or enemy On destroyed...
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sat Oct 18, 2014 2:41 am

@blackhornet
My logic was the following:
-> Pick the enemy that has the same UID as the target.targetID
-> If that enemy is destroyed or is not on screen anymore then call "setTarget" in order to find the next target.

Can you show me how to implement it correctly in C2' events ?
Also, do you know how can I check if there is any enemy on the screen ?
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Sat Oct 18, 2014 3:18 am

Triggers happen outside of the event loop so you can't use them as conditions as you did in 17,21,27. They generally need to be top level, and you do you logic below it. This is closer to what you want: event 43.

In 46, you need to release and then re-target. You may need to shuffle for your rules.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sat Oct 18, 2014 6:22 pm

@blackhornet
Thank you, but still it doesn't work how it should. If I destroy an enemy that is not targeted then I destroy the targeted enemy, the target remains in the same place in "targetMode" 1 and 2 .
I tried to add "[invert] Object with UID target.targetID exists", after "enemy - On destroyed" but no luck ... That brings me to the question: How can I check when an object with a specific UID is destroyed ?

For some reason, the "setTarget" function still picks the UID of the destroyed object.
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Sat Oct 18, 2014 7:11 pm

Some refinements.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sat Oct 18, 2014 10:49 pm

@blackhornet
Thank you again, but is still not working how it should:
targetMode=1 -> target is destroyed when any enemy is destroyed (not only the targeted one)
targetMode=2 -> works as intended
targetMode=3 -> target is destroyed when an enemy is destroyed if the playerBox doesn't move

I can't figure how to do it correctly... I tried "[invert] Object with UID target.targetID exists" (if that object doesn't exist) then call function "setTarget" (depending on "targetMode").

Either there is an error in my logic, or there is a bug in C2, because I tried a lot of walkarounds, but no luck so far :(
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Sat Oct 18, 2014 11:50 pm

It's the annoying "can't pick until next top level event" feature of C2 getting in the way. Using visibility instead of create/destroy makes things easier.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sun Oct 19, 2014 8:04 pm

@blackhornet
Thank you :) It works perfectly

Can you explain me the following:
-> What do you mean by "It's the annoying "can't pick until next top level event" feature of C2 getting in the way. Using visibility instead of create/destroy makes things easier." ? I see that you've made the enemy invisible when is destroyed as a walkaround.
-> Event 36: Why did you add "wait 0 seconds" (skip one frame) ?
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Sun Oct 19, 2014 8:38 pm

viewtopic.php?f=152&t=116572&p=839554&hilit=create+top+level+event#p839554

The wait can go, I think. That was part of my flailing with the Create issue.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Next

Return to How do I....?

Who is online

Users browsing this forum: Animate and 7 guests