# SOLVED Need help with AI of pirate ships

Get help using Construct 2

### » Fri Jan 11, 2013 6:39 pm

part of the problem as I understand angle in C2. is that what your looking for is relative angle to the ship, but angle itself is always going to be determined based on angle that 0 is always point to the right.

If your relative angle math doesn't come out right your going to get some strange results or no result at all. This is why I suggest the easy way. It increase your object count, but it is easier to implement.

https://dl.dropbox.com/u/14087254/lazyshipturn.capx

sorry. But I spent about 20m tinkering with the method you want. I decided I didn't want to pull out the calculator and figure out relative angle trig when there was a vastly easier way to do it.

Go with which ever way you want, but don't forget that angles are -180 to +180. Where as your post only looks like it's going from 0 to 180.
B
94
S
18
G
9
Posts: 2,457
Reputation: 15,167

### » Fri Jan 11, 2013 7:04 pm

When the ship ends rotate and is ready to fire should look like.
B
118
S
32
G
49
Posts: 1,888
Reputation: 37,532

### » Fri Jan 11, 2013 8:12 pm

Another way would be to fire invisible bullets (bullet behaviour) every 2 seconds or so from the front and back of the pirate ship. They'd start off with the same width as the pirate ship, then gradually get bigger as they get further from the ship. This will give a triangular line of sight. If there's a hit, then rotate towards player position.

Also fire off bullets from the sides. If a side bullet hits the player (before rotation), then player is at the correct angle to fire at. If a side bullet hits the player (while rotating), then stop rotating and fire those cannons! The logic seems sound ;p

Of course, only fire the bullets when player is within a certain distance.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Fri Jan 11, 2013 8:49 pm

@procrastinator My english is poor so i dont really sure abaut this but i think you got good idea :) set sprite towards possition is easy but set side is very dificult to do delgado2013-01-11 21:05:04
B
118
S
32
G
49
Posts: 1,888
Reputation: 37,532

### » Fri Jan 11, 2013 9:44 pm

YES i got it!
B
118
S
32
G
49
Posts: 1,888
Reputation: 37,532

### » Fri Jan 11, 2013 10:45 pm

Happy to hear :) How did you do it in the end then?
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Fri Jan 11, 2013 11:34 pm

https://dl.dropbox.com/u/44710358/za%20burta%21/index.html
B
118
S
32
G
49
Posts: 1,888
Reputation: 37,532

### » Fri Jan 11, 2013 11:37 pm

Ah nice. Looking good :)
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Previous