How to Make the Ship Shoot from the Correct Side

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Slide sideways, catch items, keep your streak, beat your high score.
  • I am trying to make a top-down ship shooting game. I have made the 8-direction movement and it’s working okay, but I am facing a problem with shooting.

    I need the player’s ship to find the nearest enemy ship and shoot at it.

    For example: if the player’s ship is facing up, the right cannon would be facing 0 degrees and the left cannon would be facing 180 degrees. I have two separate image points for the right and left cannons. If the player finds an enemy ship to the right and presses the mouse click, the player’s ship should automatically fire from the right cannon. Also, if the enemy ship is found on the left side and the player presses the mouse click, the ship should automatically fire from the left cannon.

    How can I achieve this?

    8-direction events:

    Ship:

    Game video:

    webmshare.com/play/0aPdj

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Should be simple as:

    compare Anglediff(Angle(player.x,player.y,enemy.x,enemy.y)-player.angle, 0)<90
    — shoot from right cannon
    Else
    — shoot from left

    Or some variation of that.

  • Thank you.

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