Shoot within angle

Get help using Construct 2

Post » Thu Sep 20, 2012 3:14 pm

Hi!

In my Iphone game i have a tank.
I want the tank "only" to shoot when a enemy is within 5 degr of the tank turret, no matter how far the enemy and the tank turret are away from eachother.
I have seen the "is between angle conditions etc".
However i havent found a solution to this.

Anyone have some insight?
Thanx!
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Thu Sep 20, 2012 5:29 pm

Sprite has a condition to compare if it is within a certain angle.

sprite angle is with in 5 of angle(Sprite.X,Sprite.Y,Sprite2.X,Sprite2.Y): do stuff
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Thu Sep 20, 2012 5:32 pm

I tried that but it only applied to when the other sprite was on the + side of the Y.
I need something to measure the angle in full 360.
Or i am doing something wrong?
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Thu Sep 20, 2012 6:02 pm

Is the enemy "on-screen" or qhen you say no matter how far, that includes "off-screen" enemies?... if it's the first scenario, maybe you can try this:

http://dl.dropbox.com/u/103248101/capx/5degrees.capx

it's just a sprite triangle-shaped acting as the aim of the tank's turret. The triangle has a 5 angle facing the tank, so anything overlapping that "aim" is within 5 of the tanks turret (that if my trigonometry doesen't fail me)

I supposed it was a top-viewed tank... Hope it works for you
Image
B
42
S
11
G
5
Posts: 269
Reputation: 10,890

Post » Thu Sep 20, 2012 9:14 pm

Thanx danuyos

Im going to try it out!
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Thu Sep 20, 2012 9:16 pm

@Nimtrix

That also seems the right way of doing things.

Thanx!
Im of testing!
B
56
S
20
G
13
Posts: 778
Reputation: 13,204

Post » Thu Sep 20, 2012 9:18 pm

Woops, accidentaly deleted my post by misclick:
[quote=Old post]You can use the anglediff expression:

[code]+System: Every tick
-> Set a to angle(Turret.X, Turret.Y, Target.X, Target.Y)
-> Set a0 to default angle

+System: Compare two values (anglediff(a, a0) <= 5)
-> Rotate towards a
+Else:
-> Rotate towards a0[/code][/quote]Nimtrix2012-09-20 21:20:08
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 18 guests