shoot only within values

Get help using Construct 2

Post » Sun Jun 17, 2012 12:32 pm

hello :D

I'm trying to make an "ai" that will only shoot at you when you are in it's "attack angle-range".

I've already worked out like 90% of it, but I have a problem!

i'm using x.angle and angle(x1,y1,x2,y2) in the "between values" condition. I increased the x.angle to each side so it's not just the 1 degree. it looks like this:

Value:       round(angle(mob.x, mob.y, player.x, player.y))
Lower bound: round(mob.Angle)-5
Upper bound: round(mob.Angle)+5

And it works (almost) perfectly :D! that, with some good-enough "set angle to you", makes a mean shooter.

The only problem is that the "angle between objects" counts from 0 t 180 and from -180 a 0. while the "object angle" is all 360 degrees. So it means that the AI can't shoot up =(!

my first attempt at solving this was to make all the numbers absolute... but there is still the issue that i will never get a match over 180 degrees. I'm also thinking that there must be a mathematical solution to this, but i'm not that good with maths.

and i wonder... why does the "angle between object" counts like that and not in normal 360? is it a feature or a mistake? :S

i'm gonna try now to "trick" the game into working this by setting the ai mirrored when looking up.. so it will never actually have to be looking up... hope it works. EDIT: it doesn't >_<! (i'm gonna try mixing values now...)


https://dl.dropbox.com/u/20613220/test_aim.capx

here is the file i'm testing this on =) Sargas2012-06-17 12:39:55
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Sun Jun 17, 2012 12:43 pm

i have recently been looking at the "is between angle" system , and had many difficulties, but now i found how to do it and can be used very well in this example

example
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Sun Jun 17, 2012 12:52 pm


i have edited your capx and hope its what you want i made it with 1 event:
https://dl.dropbox.com/u/67034121/scirra%20construct2/test_aim.capxzsangerous2012-06-17 12:54:04
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun Jun 17, 2012 12:57 pm

@vtrix that is just perfect!!! thank you soo soo much :D!!!!! pure love to you :D!!!!!!!!!... and I feel embarrased, it seems really simple the way you did it :D

now i wonder how many times I've overcomplicated stuff like this D:





@zsangerous... you gotta be trolling me with that? thanks anyway ^^Sargas2012-06-17 13:01:13
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Sun Jun 17, 2012 1:06 pm

isn't that the problem? :P it shoot when you are in his range ...


but i have an idea why don't you put a sprite on the enemy as the range and when the player in that sprite it will shoot and make that sprite with 0 opacity or even you can make it like a light this will be more easier than what you do ^^
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun Jun 17, 2012 1:19 pm

haha, i thought of that, but i wanted a proper clean solution :D
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Sun Jun 17, 2012 1:39 pm

glad you like it :)
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028


Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, MPPlantOfficial and 20 guests