How do I control bullet instance better?

0 favourites
  • 4 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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!

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)