Calculate the angle to fire to hit enemy

Get help using Construct 2

Post » Tue Jan 15, 2013 3:22 pm

That's some comment. My brain just melted with all the trig.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Tue Jan 15, 2013 6:22 pm

In terms of making the AI less accurate, I needed this in my case, because I have ships firing several lasers at once. Obviously if they all just fire at the precise angle, they'll overlap each other and just appear as one laser, which isn't what I was after. But the simplest answer for me was to just add a random angle to the result, somewhere between -5 and +5, so give a nice spread of lasers.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Tue Jan 15, 2013 6:24 pm

Thanks for that capx Yann. The amount of comments are very useful for helping to understand how this works. To be honest, in my case, I'm fairly happy with just pasting the code into my code, all that math hurts my brain. But it's good to know it's doing exactly what I wanted :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Tue Jan 15, 2013 7:28 pm

Another bit that would make a difference as well in stopping the AI from being quite so good is the bullet speed itself. If it is too much faster than the player movment speed, there isn't going to be much they can do to avoid being hit.

So throwing off the accuracy a bit will help much, but you may also want to toy with bullet speeds to make sure it still feels fun in terms of having a chance to dodge bullets that way a good player can still have the rush of living on the edge and flying as close as they dare to the path of the enemy bullets. Just a thought, I know it doesn't help in terms of the overall objective of predictive targeting, just more along the lines of fun factor.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Tue Jan 15, 2013 7:39 pm

You're right, in my game at least that's becoming a factor. The enemy ships are faster than the player and the bullets are faster too, making them hard to dodge (impossible if the enemy gets right ontop of the player). But if I make them too slow, it's too easy to just run away. Difficult to balance, but hopefully I'll find the right balance with endless tweaking :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Jan 16, 2013 10:56 am

Hello, back again.

I got the system working properly with the targeting, however, I then thought about having the enemy able to target the weapons on the ship to disable them.

This caused an issue in the sense that the turrets do not actually have their own speed or moving angle, as they are pinned, or simply always set to a certain position of a moving object, which is then moving around on its own. I considered having a variable on the item which reads off of the moving sprites speed/moving angle, and then feeding that into the turrets. However, if the sprite is rotating, the turret speed is increased even more.

Please click here to see an example...

You can move the blue targets around using the arrow keys, and you should see that they are always being hit... however, if you move them right off screen, the pink target is very rarely hit.

Is there a way to improve this using @sqiddsters method, as it only uses one variable (at the moment) and only a couple of lines.

Would be greatly appreciated.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 16, 2013 6:26 pm

I'll have a look at the capx when I get home. If I don't reply it means I've forgotten so just @sqiddster me again :P
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Jan 17, 2013 5:11 pm

I've still not had any luck - you @sqiddster?

I've made it less accurate, but not smooth (it's very shaky). I'll figure that out next :)
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Thu Jan 17, 2013 6:06 pm

Dang, I forgot. I'll @sqiddster myself so I remember.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Jan 17, 2013 8:08 pm

Does the problem lie in the revolving object? Because you'll need a new and more complicated algorithm to deal with revolution!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: nimos100, Yahoo [Bot] and 21 guests