Artillery game help

Get help using Construct 2

Post » Thu May 22, 2014 7:14 am

how do u check and compare distance between 2 objects ?
B
7
Posts: 30
Reputation: 333

Post » Thu May 22, 2014 8:28 am

int(distance(Object1.x,Object1.y,Object2.x,Object2.y))
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu May 22, 2014 9:18 am

@lolpaca

Can you help me look at this ? Im not sure if its correct ... thanks!
You do not have the required permissions to view the files attached to this post.
B
7
Posts: 30
Reputation: 333

Post » Thu May 22, 2014 11:08 am

Sure, I'll take a look later
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu May 22, 2014 8:57 pm

OK, first of all holy crap that's a lot of complicated maths you had going on there under the shooting AI :o If you can get it to work that way that's cool, I just tried my lazy way though. After adding a "Last shot distance" to the Text object, I did some testing and noted down some relative angle/distances.

The furthest you can shoot is 503 pixels at around angle 43 (where 0's the lowest angle possible, 80 the highest). At angle 0, you shoot 124; at angle 80, you shoot 169. I noted down the distances for every 10 angles from 40-80 (since I assume you want your enemies shooting into the air, not straight forward). Then for the enemies, I just used these distances, detected the distance between the 2 ships and set the angle accordingly every 10 increments of angles (adding 185, 180 cos we're firing the other way, and another 5 to get a midpoint).

Also added the Pin behaviour to your turrets and made the enemy ship a container of them; now every time you add an enemy ship to the layout it'll come with two turrets which are linked to that particular ship, which can be handy! Added another layout called "unused", which is a good place to hold stuff that only exists in containers, otherwise it can mess stuff up on your main layout as it automatically spawns everything associated with that container :P

As I said, this is my really scrappy lazy way, the enemies aren't 100% accurate but I think that's more realistic :D You can probably improve it by figuring out the neat way; ie finding the formula for the curve of the projectiles.

Hope this helps and good luck with it, I had fun playing with it! :D
You do not have the required permissions to view the files attached to this post.
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Fri May 23, 2014 12:42 am

@lolpaca
thanks alot bro ! this problem had me in a slump for quite some time !

BTW do you know how to set a reload function for the player so that the player cant spam the spacebar to keep firing non stop ? I just cant get it to work. Thanks!
B
7
Posts: 30
Reputation: 333

Post » Fri May 23, 2014 6:18 am

Add a Boolean ("Reloading" or something). Then, in your player shooting event, add the condition "Player is not Reloading". In the actions for that event, set Reloading to True at the top, then at the bottom add "Wait 5 seconds" (or whatever) and Set Reloading to False. Actions trigger in order from top to bottom so that should work
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Fri May 23, 2014 6:29 am

yeah i managed to make the reload work with something similar with your advise. Just that sometimes if pressing the space bar fast enough it is still able to fire twice instead of once.

Im wondering if its a bug? I got 2 different save files of the capx but i didnt change any of the code. In 1 of the capx my events is able to get the aircraft to drop like a stone after getting hit while the other capx the aircraft just get destroyed. I checked the events and i didnt change anything. Is it a bug ?
B
7
Posts: 30
Reputation: 333

Post » Fri May 23, 2014 7:40 am

I don't think it's a bug in Construct, if that's what you mean... it's almost certainly something in your events, just check and recheck them and you'll find it. It might help to read up on events and stuff and make sure you're understanding what all your conditions and whatnot are doing.

https://www.scirra.com/tutorials/292/gu ... t-features
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Previous

Return to How do I....?

Who is online

Users browsing this forum: ketramtu18 and 7 guests