How do I make an enemy have "bad aim"

Just started using Construct 2? Post your questions here

Post » Mon Oct 30, 2017 8:18 am

I currently have an enemy that always faces toward the player and shoots a burst of bullets every so often. This works ok but I would like to add some variety and randomness in the bullets to make it more interesting. I'm seeking advice on what would be the best way to do this.
B
13
S
7
Posts: 34
Reputation: 1,717

Post » Mon Oct 30, 2017 9:53 am

You can add a random number to the bullet's angle of motion.
It could be a simple random(-15,15) on every shot, this will make bullets to fly in 30 degrees cone.

Or you can do something more complex like this:
choose(0, random(-5,5), choose(-1,1)*random(20,30))

This will make some shots 100% accurate, some not too accurate and some very inaccurate.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
126
Posts: 1,761
Reputation: 67,343

Post » Mon Oct 30, 2017 10:39 am

Also, you could use @dop2000 solution, which is perfect, together with a instance variable for the enemies, like "skill", so you could set the range of accuracy for each enemy individualy and it would be consistently bad, good or average, for the whole of his existence in the game. This way you could even improve a enemy's skill whenever he hit the player or survived an encounter, making it look like they're learning and improving.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

Post » Mon Oct 30, 2017 6:48 pm

@brunopalermo
Thank you, I had never considered something like having an enemy have a skill level and even learning and improving as the game goes on. I will definitely be using this.

@dop2000
Thanks for both examples. I really like the complex one, that is going to come in very handy.

I have one problem though and it's probably something very simple about angles that I'm overlooking. Here's what I'm using below:
Image

When I have 'enemybullet's behavior at 'set angle=no' the bullets shoot out with the random cone just how I want it but not towards the player.
When 'set angle=yes' the bullets shoot toward the player but it ignores the set bullet angle action and the shots remain in a straight line.
What am I doing wrong here?
B
13
S
7
Posts: 34
Reputation: 1,717

Post » Mon Oct 30, 2017 7:13 pm

Could you share the capx, so I can reproduce the error and do some testing?

Cheers!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

Post » Mon Oct 30, 2017 8:34 pm

Yes, here is a capx highlighting the part I'm working on.

https://www.dropbox.com/s/5ubpw0l5vp7ce ... .capx?dl=0
B
13
S
7
Posts: 34
Reputation: 1,717

Post » Tue Oct 31, 2017 2:28 am

Keep "Set angle=Yes" in Bullet properties and replace "Enemybullet Set Bullet angle of motion..." with this:

Enemybullet -> Set Angle to (self.Angle+random(-15,15))

So when a bullet is spawned, its angle is initially the same as enemy's angle. Then you adjust it by random number of degrees. And then it will fly in that direction because of "Set angle=Yes" setting.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
126
Posts: 1,761
Reputation: 67,343

Post » Tue Oct 31, 2017 5:09 am

Perfect. Thank you dop2000.
B
13
S
7
Posts: 34
Reputation: 1,717

Post » Tue Oct 31, 2017 10:41 am

And here's an example with a simple skill system. I added 2 more enemies and their skill levels are 10, 25 and 75. You can tweak the values and see how precision changes. Precision will also decrease automatically with distance since a small deviation at the end of the gun means a bigger deviation the further the enemy is, which is pretty realistic. :)

https://www.dropbox.com/s/40ukw8mlhxql0 ... .capx?dl=1

Cheers!
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

Post » Tue Oct 31, 2017 6:13 pm

Very cool. Thanks for taking the time to do that brunopalermo.
B
13
S
7
Posts: 34
Reputation: 1,717


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest