playMaker

Author Topic: How to work with a tank turret?  (Read 1675 times)

077asb20

  • Playmaker Newbie
  • *
  • Posts: 2
How to work with a tank turret?
« on: July 08, 2019, 10:30:17 PM »
Hi all. I am trying to build a first person tank game. As you can see in the attached video, I have used a smooth look at action to get the turret and gun to follow where I point my mouse, however, I cannot figure out how to constrain the gun to the vertical axis. Right now it just follows anywhere. I just want the gun to move up and down to where I point the camera. Help?


daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: How to work with a tank turret?
« Reply #1 on: July 08, 2019, 11:52:43 PM »
It can be a pain with negative numbers and looping back the number (so it goes up but goes back to 0 while still going up, etc).

To get around this, recently I dodged up a solution which uses colliders. Basically you have a roof and floor collider above and below the turret, and so when the turret bumps in to it, you then 'disconnect' the action which controls the movement. So for example your barrel moves up, touches the roof, then your FSM goes from a state which allows you to use input to move up and down, to one that only allows input to move down.

Works smoothly on a FPS character I made.
« Last Edit: July 08, 2019, 11:54:21 PM by daniellogin »

077asb20

  • Playmaker Newbie
  • *
  • Posts: 2
Re: How to work with a tank turret?
« Reply #2 on: July 09, 2019, 01:39:15 PM »
It can be a pain with negative numbers and looping back the number (so it goes up but goes back to 0 while still going up, etc).

Works smoothly on a FPS character I made.

How do I do that in playmaker? I also need to limit gun arc and gun depression so it doesn't go through the ground of through the top of the turret

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: How to work with a tank turret?
« Reply #3 on: July 09, 2019, 10:58:03 PM »
I made a diagram to graphically demonstrate what I'm saying.

If you look at the picture, you will see two red rectangles; One represents a Trigger Collider above the barrel, and the other is a trigger collider below the barrel.

The barrel itself will need a collider. Just the barrel (the part you want to limit). You could just slap a box or cylinder around it if you aren't using the mesh itself or etc.

Have the up and down input and it's resulting input in the same state. As in get the vector for your controller or what not every frame, then do your rotation every frame using those vectors. This system won't work if you are waiting for your input then sending to a new state to apply the movement.

OK so now in the diagram, you will see the turret is looking up to the point that the barrel collider just touched the roof collider. The same state which is getting your Up and Down input and applying the motion also has a Trigger Event waiting for the barrel (specifically) to Enter. As soon as it enters, it sends an event to your next state.

Now your next state is pretty much the same BUT it is MISSING the Up input. Pressing up now does nothing... so it's locked at that point. You can however still press down. When you do press down, you will Exit the trigger, and thus send the trigger event to go back to the first state (which has Up and Down again).

You do the same with down. You have the Enter trigger event for the floor which goes to a state which has Up but not down.