How do I create a player-controlled turret

0 favourites
  • 15 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hey everyone!

    I'm working on a landscape-oriented project right now and I would really like to create a turret which can be controlled by a player. Unfortunately, I don't know how to do it, so I would like to know if anyone here knows any good tips on how to accomplish this.

  • What type of control do you want? Do you want the turret to point at the mouse or turn with the keyboard?

  • I'd like to make it turn with the keyboard, hopefully. Preferably with the left and right arrow keys (It's only supposed to move on a limited angle)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Auto fire, or by key press?

  • I want it to be constantly firing, like a turret-mounted flashlight, so to speak.

  • 1 - Create a variable called angle and set it to 0. This will represent a value of 0 to 359.

    2 - When a direction key is pressed, add/subtract a value from angle depending on how much you want the turret to turn.

    3 - Set the sprites angle to the value in angle.

    4 - When angle >= 360, set angle = angle - 360. This keeps angle within the 0 to 359 values.

    5 - Set the angle of the spawned "bullet" items to the same value as the turret.

  • Okay, here is an example that allows you to place a turret anywhere on the screen and have it limited by min and max rotation range. It's saved as the latest beta version.

  • I put two turrets in there so you could see how the min and max values could be set on a per-turret basis.

  • That's great! Do you guys know of a way to interact with the turret? Like, only being able to rotate it if the player decided to press E right next to it in order to use it, while also forcing the player to stand still while he interacts with it. Also, any idea on how to make the turret fire constantly, regardless of whether I'm using it or not? Like a laser beam, or something similar.

  • I'll see what I can do about this today.

  • Okay! New version inbound in t-minus 5, 4, 3, 2......

    BLAM.

    So move your character with the arrow keys and jump in or out of a turret using the space bar.

  • Oh! One other thing. Right now the player has to be overlapping the turret for it to work.

  • Great! Thanks a lot! One last question though. Do you know if it's possible to keep the turrets shooting even if the player isn't controlling them?

    Other than that, it's all good! I'm really glad you were able to help.

  • You can set a boolean local variable called something like SHOOTING and set it to true when the player starts the turret shooting. Then, use it as the condition for the turrets shoot action.

  • What type of control do you want? Do you want the turret to point at the mouse or turn with the keyboard?

    hi Egoant is it posible you can make an example with the turret to point at the mouse, i have set "set angle toward (mouse.x,mouse.y) i just need the turrent to stop rotating and remain fixed if the mouse causes the angle to be above say 260 or below 45.

    Also it will need need to work when the turrent faces the other direction while is mirrored, thanks a lot in advance

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