0 Favourites

SOLVED Need help with AI of pirate ships

  • If player is too far nothing happen but if is too close to oponent, oponetn will automatically turn to right side like ships on sea fights

    <img src="https://dl.dropbox.com/u/44710358/box.png" border="0" />

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • If distance( Pirate.X, Pirate.Y, Player.X, Player.Y ) < 50

    | If angle( Pirate.X, Pirate.Y, Player.X, Player.Y ) < 0

    | If angle( Pirate.X, Pirate.Y, Player.X, Player.Y ) > 180

    | Pirate rotate to the left

    |

    | If angle( Pirate.X, Pirate.Y, Player.X, Player.Y ) < 180

    | If angle( Pirate.X, Pirate.Y, Player.X, Player.Y ) > 0

    | Pirate rotate to the right

    | = "if distance" event block.

    You'll need to adjust the angle tests if you want it within a certain range.

  • procrastinator is this is right? because nothing happens with pirate ships<img src="https://dl.dropbox.com/u/44710358/logo.png" border="0" />

  • That's right, but I think my logic is flawed. I didn't take into account the angle the player may be facing. Give me a short while. Brain fog ;)

  • sure, well i add rotate with clockwise but this is not good solution because ship will be rotated over and over without smooth rotate. I think this part is dificult to do

  • I don't know about you guys, but I like to be lazy. Instead of distance checks. I like to use invisible sprites(visible with low opacity for testing) that are pinned to the object(also with the new container object).

    That way you can create your collision polygon either by setting the collision points or creating an image shape to match your above example.

  • jayderyu we got already check system but how to set auto rotate ship

  • I don't know about you guys, but I like to be lazy. Instead of distance checks. I like to use invisible sprites(visible with low opacity for testing) that are pinned to the object(also with the new container object).

    That way you can create your collision polygon either by setting the collision points or creating an image shape to match your above example.

    Yeah I only just thought of that and came back to mention it. You beat me to it ;p

    delgado, I just thought... if it's a pirate ship, wouldn't it fire from the sides? I mean, they'd do the opposite to what you're actually asking - they'd rotate so their sides are facing the player since the sides are where the cannons are.. right?

    Anyway, you can use

    PirateShip.Rotate To Position (Player.X, Player.Y)

    to turn the ship to the player's position.

  • procrastinator yes pirate ship have to turn sideways to the player Because cannons are on left and right sides.

  • 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.

    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.

  • When the ship ends rotate and is ready to fire should look like.<img src="https://dl.dropbox.com/u/44710358/2.jpg" border="0" />

  • 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.

  • 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

  • YES i got it!

  • Happy to hear :) How did you do it in the end then?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)