How do I control bullet instance better?

Get help using Construct 2

Post » Sat Dec 26, 2015 11:50 pm

I have an enemy who walks back and forth on the level and shoots every few seconds. The enemies are spawned randomly every few seconds. The bullet's direction is determined by whether the enemy is mirrored or not. If there are multiple enemies on the level, the bullet's direction gets all messed up. For example, all of the bullets on the level going right. How can I control this better? Here's what I've got. Image
B
3
Posts: 6
Reputation: 191

Post » Sun Dec 27, 2015 2:40 am

It might help to read the manual for "picking" instances [https://www.scirra.com/manual/75/how-events-work].
Also search the tutorials and forums for "picking".

As your code stands the bullet objects all go right when X is mirrored because nothing is picking which instances of the bullets.

One way would be to give your bullet an instance variable of JustSpawned=0, have your code condition JustSpawned=0 when deciding its direction and change it to JustSpawned=1 once it has its direction assignment... this way old bullets will ignore direction changes and changes will happen so quick duplicates shouldn't occur.. but if they did you would need to tighten the "picking" conditions more.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
51
S
14
G
8
Posts: 593
Reputation: 8,558

Post » Sun Dec 27, 2015 4:40 am

chrisinfinger wrote:It might help to read the manual for "picking" instances [https://www.scirra.com/manual/75/how-events-work].
Also search the tutorials and forums for "picking".

As your code stands the bullet objects all go right when X is mirrored because nothing is picking which instances of the bullets.

One way would be to give your bullet an instance variable of JustSpawned=0, have your code condition JustSpawned=0 when deciding its direction and change it to JustSpawned=1 once it has its direction assignment... this way old bullets will ignore direction changes and changes will happen so quick duplicates shouldn't occur.. but if they did you would need to tighten the "picking" conditions more.


Thanks for the help. I read up on that manual but couldn't figure out what else to do to tighen my "picking", so I just went with your second suggestion for now. It seems to be working fine currently. Seriously, thanks!
B
3
Posts: 6
Reputation: 191

Post » Mon Dec 28, 2015 1:27 am

One method of tightening would involve using instance IDS (UID) numbers instead, grabbing it when the bullet is spawned and then using that ID directly when setting direction... but this is probably overkill in your project.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
51
S
14
G
8
Posts: 593
Reputation: 8,558


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests