playMaker

Author Topic: 3rd Person Shooter Aiming Help [SOLVED]  (Read 5828 times)

Stonebolt

  • Playmaker Newbie
  • *
  • Posts: 15
3rd Person Shooter Aiming Help [SOLVED]
« on: October 26, 2014, 10:13:15 AM »
Hello!

I'm currently setting up character controls for a 3rd person shooter and am having trouble properly getting the aim system input to work how I want.

I'm using a 2D Simple Directional blend tree to control a 3x3 box of 9 different aim animations (Aim straight, aim 45 degrees to the right, aim 45 degrees up, ect). I am then using an FSM to bridge to aiming from an idle command using Get Button Down.

Everything runs and works properly but the problem I'm having is I'm using Get Mouse X and Get Mouse Y to get input from the mouse. This means when I click "Fire1", the character properly goes from idle to the aim state, but the character starts off aiming in a location directly relative to where the mouse is, which isn't really what I want.

I'm trying to get the mouse to start at 0,0 (when you press aim and just point forward like you would expect in a 3rd person shooter) and then have the mouse input control it from there, rather than just having it aim wherever the invisible mouse cursor is when you first press it. (The animation in the center of the 2D blend tree aims in the desired 0,0 position)

Any other way of communicating with mouse input other then Get Mouse X/Y or ideas in general would be appreciated.

Thanks!
« Last Edit: November 02, 2014, 02:32:56 PM by Stonebolt »

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
Re: 3rd Person Shooter Aiming Help
« Reply #1 on: October 30, 2014, 11:39:29 PM »
You could lock the cursor so the aim sight points always at the center of the screen -which is the common case for TPS...

Stonebolt

  • Playmaker Newbie
  • *
  • Posts: 15
Re: 3rd Person Shooter Aiming Help
« Reply #2 on: October 31, 2014, 09:39:41 PM »
I tried doing that but the Get Axis would always change the floats to (0,0) every frame. I'll probably look into it more.

cmonroy

  • Playmaker Newbie
  • *
  • Posts: 34
Re: 3rd Person Shooter Aiming Help
« Reply #3 on: November 01, 2014, 04:40:54 PM »
Not sure if I understood correctly what is your problem, but having traveled this road I thinl I can provide you with some ideas:

- Coordinates X and Y are easily transformed into your AimDirection and AimHeight. However, you also need another axis to identify how far is the aimed target from the camera in order to specify a point in your scene. If there is any object at the end of your aiming line, everything is cool. If, in the other hand, there is the possibility that your aiming line does not intersect any object at a certain time, most routines are useless. To solve this you need to create a dummy target and position it at a certain distance from your aiming start. Make an FSM to move this target using the values you've got from the Mouse position. This insures you'll always have an object at the end of the raycast. Don't forget to parent this dummy target to your character so its position remains constant regardless of on which direction you move.

- The human player is aiming at the target looking through the camera which has an offset position from the character playing  the aiming animation. Hence, you need to provide your character with a LookAt object which evidently is different from the position (Vector3) and rotation (Quaternion) used by the camera. If you are aiming from your character, a parallelax error will be noted whereas if you are aiming from the camera it will not. The bullet, however, and assuming you are using a firearm will come from your weapon model as the start of its own aiming line and will extend to the postion of your dummy target.

- The distance at which you are going to position your dummy target depends on your game, because the Mouse position plus the target distance will provide you with an angle. If the real target is too close or too far away, you may miss it because the angle between your real target and your dummy target are too different.

Once you have solved this,  your have:

- An origin position and rotation
- A destination position and rotation
- An angle between the origin and the destination

Normalize the angle so the max negative and max positive for the VerticalAim and HorizontalAim are between -1 and +1, and feed this values to your animator FSM, which then could use them to play the correct animation.

Get Axis is for reading your input speed and direction (what makes your character move). When you press any movement key or stick, Get Axis gets its normalized value and hence you can't use them for aiming... If you are controlling something like a turret, you need to feed the Get Axis Horizontal and Get Axis Vertical into other variables which ADD or SUBTRACT some specific value to move your weapon in the intended direction.

Stonebolt

  • Playmaker Newbie
  • *
  • Posts: 15
Re: 3rd Person Shooter Aiming Help
« Reply #4 on: November 02, 2014, 02:29:37 PM »
Wow thanks!

I didn't think about the need for a gameobject in the distance. It's also really important for getting the camera to behave properly while in aim mode. I got a good setup for that by parenting it to the characters chest bone while aiming with Smooth Look At.

Anyway everything working just about perfectly.

Thanks again!