Search Unity

Third person cover controller

Discussion in 'Assets and Asset Store' started by EduardasFunka, May 23, 2017.

  1. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    279
    Horse animset pro would be killer for tpcs, suits it well, and malbers animations have great support and is just a stand up good guy. Playmaker integration would be cool . Rewired could be a easy one to do, that would add a lot of value, and open the door for multiplayer. Inventory pro is active which would branch into quest pro.
     
    Rahd and jwsntn170 like this.
  2. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    71
    Had a request for adding sprint to the mobile third person controls. I wanted to share it here hope it helps.



    MovementJoystick.cs
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using UnityEngine.UI;
    5.  
    6. namespace UnityStandardAssets.CrossPlatformInput
    7. {
    8.     public class MovementJoystick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
    9.     {
    10.         public enum AxisOption
    11.         {
    12.             // Options for which axes to use
    13.             Both, // Use both
    14.             OnlyHorizontal, // Only horizontal
    15.             OnlyVertical // Only vertical
    16.         }
    17.  
    18.         public int MovementRange = 100;
    19.         public AxisOption axesToUse = AxisOption.Both; // The options for the axes that the still will use
    20.         public string horizontalAxisName = "Horizontal"; // The name given to the horizontal axis for the cross platform input
    21.         public string verticalAxisName = "Vertical"; // The name given to the vertical axis for the cross platform input
    22.  
    23.         Vector3 m_StartPos;
    24.         bool m_UseX; // Toggle for using the x axis
    25.         bool m_UseY; // Toggle for using the Y axis
    26.         CrossPlatformInputManager.VirtualAxis m_HorizontalVirtualAxis; // Reference to the joystick in the cross platform input
    27.         CrossPlatformInputManager.VirtualAxis m_VerticalVirtualAxis; // Reference to the joystick in the cross platform input
    28.         public bool walk;
    29.         public Toggle autoRun;
    30.         public string buttonName;
    31.         public GameObject runArrow;
    32.  
    33.         void OnEnable()
    34.         {
    35.             CreateVirtualAxes();
    36.         }
    37.  
    38.         void Start()
    39.         {
    40.             m_StartPos = transform.position;
    41.         }
    42.  
    43.         void UpdateVirtualAxes(Vector3 value)
    44.         {
    45.             var delta = m_StartPos - value;
    46.             delta.y = -delta.y;
    47.             delta /= MovementRange;
    48.             if (m_UseX)
    49.             {
    50.                 m_HorizontalVirtualAxis.Update(-delta.x);
    51.             }
    52.  
    53.             if (m_UseY)
    54.             {
    55.                 m_VerticalVirtualAxis.Update(delta.y);
    56.             }
    57.             //When the Joystick reaches the maximum up value of the available range which is 1
    58.             //the player will start running untill the joystick moves below 0.7 return to walking.
    59.             //This can also be repetted for backwards and strafe...
    60.             if (delta.y <= 0.7 || delta.y == 0)
    61.             {
    62.                 walk = true;
    63.             }
    64.             if (delta.y == 1)
    65.             {
    66.                 walk = false;
    67.             }
    68.  
    69.             if (walk)
    70.             {
    71.                 SetUpState();
    72.             }
    73.             if (!walk)
    74.             {
    75.                 SetDownState();
    76.             }
    77.         }
    78.  
    79.         void CreateVirtualAxes()
    80.         {
    81.             // set axes to use
    82.             m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
    83.             m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
    84.  
    85.             // create new axes based on axes to use
    86.             if (m_UseX)
    87.             {
    88.                 m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
    89.                 CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
    90.             }
    91.             if (m_UseY)
    92.             {
    93.                 m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
    94.                 CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
    95.             }
    96.         }
    97.  
    98.  
    99.         public void OnDrag(PointerEventData data)
    100.         {
    101.             Vector3 newPos = Vector3.zero;
    102.  
    103.             if (m_UseX)
    104.             {
    105.                 int delta = (int)(data.position.x - m_StartPos.x);
    106.                 delta = Mathf.Clamp(delta, - MovementRange, MovementRange);
    107.                 newPos.x = delta;
    108.             }
    109.  
    110.             if (m_UseY)
    111.             {
    112.                 int delta = (int)(data.position.y - m_StartPos.y);
    113.                 delta = Mathf.Clamp(delta, -MovementRange, MovementRange);
    114.                 newPos.y = delta;
    115.             }
    116.             transform.position = new Vector3(m_StartPos.x + newPos.x, m_StartPos.y + newPos.y, m_StartPos.z + newPos.z);
    117.             UpdateVirtualAxes(transform.position);
    118.         }
    119.  
    120.  
    121.         public void OnPointerUp(PointerEventData data)
    122.         {
    123.             transform.position = m_StartPos;
    124.             UpdateVirtualAxes(m_StartPos);
    125.             runArrow.SetActive(false);
    126.         }
    127.  
    128.  
    129.         public void OnPointerDown(PointerEventData data)
    130.         {
    131.             if (autoRun.isOn)
    132.             {
    133.                 autoRun.isOn = false;
    134.             }
    135.         }
    136.  
    137.         void OnDisable()
    138.         {
    139.             // remove the joysticks from the cross platform input
    140.             if (m_UseX)
    141.             {
    142.                 m_HorizontalVirtualAxis.Remove();
    143.             }
    144.             if (m_UseY)
    145.             {
    146.                 m_VerticalVirtualAxis.Remove();
    147.             }
    148.         }
    149.         //Calls the string to reference a corrisponding input set in the Player Settings.
    150.         //For this example our string for the buttonName field is "Run"
    151.         public void SetDownState()
    152.         {
    153.             CrossPlatformInputManager.SetButtonDown(buttonName);
    154.             runArrow.SetActive(false);
    155.         }
    156.         public void SetUpState()
    157.         {
    158.             CrossPlatformInputManager.SetButtonUp(buttonName);
    159.             runArrow.SetActive(true);
    160.         }
    161.  
    162.         //From the toggle we can place the joystick object in the On Value Changed field
    163.         //and call this function setting the player to run automatically.
    164.         public void SetToggleState()
    165.         {
    166.             Vector3 newPos = Vector3.zero;
    167.             if (autoRun.isOn)
    168.             {
    169.                 transform.position = new Vector3(m_StartPos.x + newPos.x, m_StartPos.y + 20, m_StartPos.z + newPos.z);
    170.             }
    171.             else
    172.             {
    173.                 transform.position = new Vector3(m_StartPos.x + newPos.x, m_StartPos.y + 0, m_StartPos.z + newPos.z);
    174.             }
    175.             UpdateVirtualAxes(transform.position);
    176.         }
    177.     }
    178. }
     
    Lay84, Sarhanbh and Rahd like this.
  3. raziel786

    raziel786

    Joined:
    May 6, 2014
    Posts:
    20
    Wonder if anyone can help me? I am using 3rd Person Cover Controller for my mobile game however I am currently having issues with my enemy character animation (see attached image). When i disable "IK Enabled" the character model appears fine however will not shoot or attack. I am using the same animator on my player and it works correctly. Any ideas?
     

    Attached Files:

  4. flowe321

    flowe321

    Joined:
    Oct 27, 2016
    Posts:
    11
    Having trouble getting the second gun to fire in with the dual wield property. It only shoots the right handed gun. Any ideas on fixes?
     
  5. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    279
    No kidding he isnt shooting, he was s busy with..... other things
     
  6. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    9
    Does anyone know why the ai sometimes glides along the floor?
     
  7. Sarhanbh

    Sarhanbh

    Joined:
    Apr 15, 2015
    Posts:
    40
    any image for that plz? sometimes it is come from non static floor or not navmesh backed
     
  8. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    9
    I'd have to attach a video, and not sure that would help.

    It happens every few seconds, it seems to last for a few seconds as well.

    I'd added a NavMeshAgent to my ai characters, as I thought this was needed. It seems the issue has gone now I removed it.

    I'm a bit confused, I realise the ai switch between waypoints/zones and unity navigation, but I thought NavMeshAgent was needed to use navigation.

    It seems removing the NavMeshAgent component has fixed the sliding issue, but I don't see how they use pathfinding without it.

    If someone can clarify I'd appreciate it.

    I feel I should add, this is the best shooter ai I've seen, and I've used a lot of assets. I'd be very upset if this asset doesn't continue in development.
     
  9. ypanos

    ypanos

    Joined:
    May 5, 2014
    Posts:
    1
    Hi guys i am trying to setup my character based on the Cowboy Version 1.6.
    Basically there is no clear video how to do this from scratch migrating from one character to the other. The videos presented at the asset store are for older version. Looking at cowboy there are a lot of scripts and objects besides the weapons to the skeleton and i have to go through all of them to figure out how to setup my character as the Cowboy.
    Is there someone that can help or at least give me a link. Otherwise i must go through everything to figure out how to setup my character.
    Thanks
     
    JBR-games likes this.
  10. HonKasumi

    HonKasumi

    Joined:
    Apr 25, 2018
    Posts:
    37
    hello there, can i get some help, i have made my character with animation and ect, nothing implemented form this asset, but im really intresting to just implement just 2 features just the zooming when having the weapon and weapon switching, could i get the help pls, i dont how how to take the codes and put it in my own character
     
  11. Sarhanbh

    Sarhanbh

    Joined:
    Apr 15, 2015
    Posts:
    40
    it not use nav mesh agent
    he use navmesh to calculate path and get points by his code. nav mesh agent calculate this directly but he don't use it
     
    DevelopGamer likes this.
  12. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    for mobile Same as Aim and move sticks , roll stick attach script to a copy of the aim joystick (remove the aim script after you transfer the same elements like control selection ..ect) place in the center of screen :
    Code (CSharp):
    1. using UnityEngine ;
    2. namespace CoverShooter
    3. {
    4.     /// <summary>
    5.     /// Takes directional vector of  camera  and input from  the touch screen and passes it to  Controller to roll  in relation of the camera angle and the player .
    6.     /// </summary>
    7.  // MoveIntensity to be removed .
    8.  
    9.  
    10.     public class RollStick : TouchBase
    11.     {  public  CharacterMotor player ;
    12.         public    float angle;
    13.         protected override void Update()
    14.         {
    15.             base.Update();
    16.  
    17.             if (Controller == null)
    18.                 return;
    19.             angle = AngleRoll (Delta)  ;
    20.             if (Delta.sqrMagnitude > float.Epsilon) {
    21.      
    22.            
    23.                 Controller.Aiming = Delta;
    24.  
    25.                 roll (new Vector3 (-Delta.x ,0,-Delta.y) );
    26.  
    27.             } else {
    28.  
    29.             Controller.HasAiming = false;
    30.                 }
    31.         }
    32.  
    33.         private void roll(Vector3 local)
    34.         {
    35.  
    36.  
    37.  
    38.  
    39.             var direction = getMovementDirection(local);
    40.  
    41.             if (direction.sqrMagnitude > float.Epsilon)
    42.                 Controller.InputRoll(Util.HorizontalAngle(direction));
    43.         }
    44.         private Vector3 getMovementDirection(Vector3 local)
    45.         {
    46.  
    47.        
    48.  
    49.  
    50.             var forward = Controller.BodyTargetInput - Camera .main.transform.forward;
    51.             forward.y = 0;
    52.             forward.Normalize();
    53.  
    54.             float angle;
    55.  
    56.             if (player.IsInCover)
    57.             {
    58.                 angle = Util.HorizontalAngle(forward);
    59.  
    60.                 if (player.Cover.IsLeft(angle, 45))
    61.                     angle = Util.HorizontalAngle(player.Cover.Left);
    62.                 else if (player.Cover.IsRight(angle, 45))
    63.                     angle = Util.HorizontalAngle(player.Cover.Right);
    64.                 else if (player.Cover.IsBack(angle, 45))
    65.                     angle = Util.HorizontalAngle(-player.Cover.Forward);
    66.                 else
    67.                     angle = Util.HorizontalAngle(player.Cover.Forward);
    68.  
    69.                 forward = Util.HorizontalVector(angle);
    70.             }
    71.             else
    72.                 angle = Util.HorizontalAngle(forward);
    73.  
    74.             var right = Camera .main.transform.right;
    75.             right.y = 0f;
    76.             Util.Lerp(ref _leftMoveIntensity, player.IsFreeToMove(-right) ? 1.0f : 0.0f, 4);
    77.             Util.Lerp(ref _rightMoveIntensity, player.IsFreeToMove(right) ? 1.0f : 0.0f, 4);
    78.             Util.Lerp(ref _backMoveIntensity, player.IsFreeToMove(-forward) ? 1.0f : 0.0f, 4);
    79.             Util.Lerp(ref _frontMoveIntensity, player.IsFreeToMove(forward) ? 1.0f : 0.0f, 4);
    80.  
    81.             if (local.x < -float.Epsilon) local.x *= _leftMoveIntensity;
    82.             if (local.x > float.Epsilon) local.x *= _rightMoveIntensity;
    83.             if (local.z < -float.Epsilon) local.z *= _backMoveIntensity;
    84.             if (local.z > float.Epsilon) local.z *= _frontMoveIntensity;
    85.  
    86.             return Quaternion.Euler(0, angle, 0) * local;
    87.         }
    88.         private float _leftMoveIntensity = 1;
    89.         private float _rightMoveIntensity = 1;
    90.         private float _backMoveIntensity = 1;
    91.         private float _frontMoveIntensity = 1;
    92.         public static float AngleRoll(Vector2 p_vector2)
    93.         {
    94.             if (p_vector2.x < 0)
    95.             {
    96.                 return 360 - (Mathf.Atan2(p_vector2.x,  p_vector2.y) * Mathf.Rad2Deg * -1);
    97.             }
    98.             else
    99.             {
    100.                 return Mathf.Atan2(p_vector2.x,  p_vector2.y) * Mathf.Rad2Deg;
    101.             }
    102.         }
    103.     }
    104. }
    if input roll is missing add it from the thirdPcontroller

    public void InputRoll(float angle)
    {
    _wantsToRoll = true;
    _rollAngle = angle;
    }
     
    Last edited: Nov 17, 2019
    satchell likes this.
  13. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    Here is a better script with delay in seconds so the player can have time to chose the roll direction .
    you can adjust other things like min delta and magnitude activation (1 or more will stop it from working )

    Code (CSharp):
    1. using UnityEngine ;
    2. namespace CoverShooter
    3. {
    4.     /// <summary>
    5.     /// Takes directional movement input from the touch screen and passes it to Mobile Controller.
    6.     /// </summary>
    7.    
    8.  
    9.  
    10.     public class RollStick : TouchBase
    11.     {  public  CharacterMotor player ;
    12.         public float Dragmin =0.5f;
    13.         public float DragActivation =0.1f;
    14.         public float slidedelay = 0.1f;
    15.         float elapsed = 0f;
    16.  
    17.         protected override void Update()
    18.         {
    19.             base.Update();
    20.             elapsed += Time.deltaTime;
    21.             if (elapsed >= slidedelay) {
    22.  
    23.                
    24.  
    25.  
    26.                 elapsed = 0;
    27.    
    28.             if (Controller == null)
    29.                 return;
    30.        
    31.             if (Delta.sqrMagnitude > DragActivation) {
    32.            
    33.                
    34.                 Controller.Aiming = Delta;
    35.                 if (Mathf.Abs (Delta.x) >= Dragmin || Mathf.Abs (Delta.y) >= Dragmin) {
    36.                
    37.                     roll (new Vector3 (-Delta.x ,0,-Delta.y) );
    38.                
    39.                 }
    40.            
    41.  
    42.             } else {
    43.          
    44.  
    45.  
    46.                 }    
    47.             }
    48.         }
    49.  
    50.         private void roll(Vector3 local)
    51.         {
    52.  
    53.  
    54.  
    55.  
    56.             var direction = getMovementDirection(local);
    57.  
    58.             if (direction.sqrMagnitude > float.Epsilon)
    59.                 Controller.InputRoll(Util.HorizontalAngle(direction));
    60.         }
    61.         private Vector3 getMovementDirection(Vector3 local)
    62.         {
    63.  
    64.              
    65.  
    66.  
    67.             var forward = Controller.BodyTargetInput - Camera .main.transform.forward;
    68.             forward.y = 0;
    69.             forward.Normalize();
    70.  
    71.             float angle;
    72.  
    73.             if (player.IsInCover)
    74.             {
    75.                 angle = Util.HorizontalAngle(forward);
    76.  
    77.                 if (player.Cover.IsLeft(angle, 45))
    78.                     angle = Util.HorizontalAngle(player.Cover.Left);
    79.                 else if (player.Cover.IsRight(angle, 45))
    80.                     angle = Util.HorizontalAngle(player.Cover.Right);
    81.                 else if (player.Cover.IsBack(angle, 45))
    82.                     angle = Util.HorizontalAngle(-player.Cover.Forward);
    83.                 else
    84.                     angle = Util.HorizontalAngle(player.Cover.Forward);
    85.  
    86.                 forward = Util.HorizontalVector(angle);
    87.             }
    88.             else
    89.                 angle = Util.HorizontalAngle(forward);
    90.  
    91.             var right = Camera .main.transform.right;
    92.             right.y = 0f;
    93.             Util.Lerp(ref _leftMoveIntensity, player.IsFreeToMove(-right) ? 1.0f : 0.0f, 4);
    94.             Util.Lerp(ref _rightMoveIntensity, player.IsFreeToMove(right) ? 1.0f : 0.0f, 4);
    95.             Util.Lerp(ref _backMoveIntensity, player.IsFreeToMove(-forward) ? 1.0f : 0.0f, 4);
    96.             Util.Lerp(ref _frontMoveIntensity, player.IsFreeToMove(forward) ? 1.0f : 0.0f, 4);
    97.  
    98.             if (local.x < -float.Epsilon) local.x *= _leftMoveIntensity;
    99.             if (local.x > float.Epsilon) local.x *= _rightMoveIntensity;
    100.             if (local.z < -float.Epsilon) local.z *= _backMoveIntensity;
    101.             if (local.z > float.Epsilon) local.z *= _frontMoveIntensity;
    102.  
    103.             return Quaternion.Euler(0, angle, 0) * local;
    104.         }
    105.         private float _leftMoveIntensity = 1;
    106.         private float _rightMoveIntensity = 1;
    107.         private float _backMoveIntensity = 1;
    108.         private float _frontMoveIntensity = 1;
    109.    
    110.     }
    111. }
    112.  
     
    satchell likes this.
  14. HonKasumi

    HonKasumi

    Joined:
    Apr 25, 2018
    Posts:
    37
    hi, sorry that i take some of your time, but may i ask you if its possible just to take some features from the asset, i have my own character that runs, jumps and hits, but i want to implement the weapon system of the asset and the switching
     
  15. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259

    those tutos playlist do cover most of the steps to make your guns work and the zoom on them .
    best approach is to have a copy of the example cowboy character and try to copy the same settings
    check for errors like null reference exception , that means you did not assign something in the camera scripts or the character scripts . it's an easy but long process .
     
  16. HonKasumi

    HonKasumi

    Joined:
    Apr 25, 2018
    Posts:
    37
    Thats exactly what i did yesterday , i put my character and the cowboy next to each other, but than i realized i need to also copy the animation and make the same because my character is small and i cant just drag and drop cowboys animation into my owns, thats thr hardest part.
    If there would be a tut that covers exactly that it would been awesome
    But thanks for letting me know im in the right path
     
  17. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    you don't have to do that , just replace the animation controller , with the cowboy one . if your character is a humanoid . i don't see any other way to do it .
     
  18. HonKasumi

    HonKasumi

    Joined:
    Apr 25, 2018
    Posts:
    37
    Hmmm My character has character controller already, but does it work when i drag just some part of the cowboy character controller and put it in my own? Im not really familiar with animation and now they work
     
  19. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    will take more time the layers and parameters tab will take time to redo . coping or dragging the stats only will not work without parameters . trying to remake the whole controller will take ages to do the transitions using the parameters .
    try to switch the controller , like make a copy of the cowboy one then replace the animations you want .
    like i said when a character is a humanoid all clips will work on it , the controller is just a big tree of animations , the animations and the character matters . can you explain what is special about your character controller , maybe there is an easy way to make it work the way you want .
     
  20. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    a strange bug found today on the Motor :

    public bool IsMoving
    {
    get { return _isMoving; } }
    will always return false even if _isMoving is true . had to switch _isMoving to public so i can detect movements
    is this the same for everyone ?
    or is it just me ?
     
  21. TotalPixel

    TotalPixel

    Joined:
    May 26, 2012
    Posts:
    19
    Hi all, I purchased this asset last year and have been working on a rather big game since. However I wanted to upgrade unity to 2019 and this template too. However I didn't want to import over all my work so only imported certain bits. Now my anims don't play correctly, as in melee freezes. Anyone figured out how to fix this without re adding the whole template.

    Thanks
     
  22. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    Hello everyone, I recently purchased the asset and from quickly scanning within this forum. It seems this community is the one who fixes outstanding issues with elements of the package.

    My question is rather simple:

    Can I use a joystick to control the character?

    My current version of unity is 2018.2.8f1 should I upgrade?

    Has anyone used playmaker with the product?
     
  23. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    for playmaker you will need to make custom script (Actions)
    as for the joystick you can map them in the Input Manager using the keyboard
    try to copy only the character controller and the animation folder from a fresh copy of the asset . (Make a copy of the project before you do this, just in case )
     
    Last edited: Nov 21, 2019
  24. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
     
  25. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    this should cover it : https://answers.unity.com/questions/318766/use-gamepad-right-analog-stick-instead-of-mouse-to.html
    when looking for guides to make the xbox controller works with unity use gamepad not joystick
    my understanding so far is you want to use controllers like for xbox with your third person cover asset , if it's mobile you are talking please let me know it's not the same as that link .

    pro builder is not the issue :( .
    @EduardasFunka
    Not sure if this bug is fixed in the beta , i'm using 1.6 still .
    so the player will get stuck if the ground check is a tricky position ( example raycast is in a hole )

    so to fix this for now i added an addition to the GroundThreshold when moving this will allow the player to scale stairs or trick terrain .

    public float GroundThresholdMoving =0.2f;
    private void updateGround()
    {
    if (_ignoreFallTimer < float.Epsilon)
    if (IsMoving) {
    findGroundAndSlope(GroundThreshold+GroundThresholdMoving);
    } else {
    findGroundAndSlope(GroundThreshold);
    }

    else
    _isGrounded = true;
    if (_isGrounded && !_wasGrounded && IsAlive && _nogroundTimer >= 0.3f)
    {
    for (int i = 0; i < _physicsListeners.Length; i++)
    _physicsListeners.OnLand();
    _nextJumpTimer = 0.2f;
    if (Landed != null)
    Landed.Invoke();
    }
    _wasGrounded = _isGrounded;
    }
     
  26. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    For anyone interested in foot Ik system here is a modified one from Filmstorm
    (i removed the Pro feature and the clip curve ... )
    Tuto :

    Test on cover shooter :

    //Copyright Filmstorm (C) 2018 - Movement Controller for Root Motion and built in IK solver
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Footik : MonoBehaviour
    {
    public Animator anim; //Animator

    private Vector3 rightFootPosition, leftFootPosition, leftFootIkPosition, rightFootIkPosition;
    private Quaternion leftFootIkRotation, rightFootIkRotation;
    private float lastPelvisPositionY, lastRightFootPositionY, lastLeftFootPositionY;
    [Header("Feet Grounder")]
    public bool enableFeetIk = true;
    [Range(0, 2)] [SerializeField] private float heightFromGroundRaycast = 1.14f;
    [Range(0, 2)] [SerializeField] private float raycastDownDistance = 1.5f;
    [SerializeField] private LayerMask environmentLayer;
    [SerializeField] private float pelvisOffset = 0f;
    [Range(0, 1)] [SerializeField] private float pelvisUpAndDownSpeed = 0.28f;
    [Range(0, 1)] [SerializeField] private float feetToIkPositionSpeed = 0.5f;
    [Range(0, 1)] public float feetToIkPositionDistance = 0.5f;

    public bool useProIkFeature = false;
    public bool showSolverDebug = true;
    [Header("Animation Smoothing")]
    [Range(0, 1f)]
    public float HorizontalAnimSmoothTime = 0.2f; //InputX dampening
    [Range(0, 1f)]
    public float VerticalAnimTime = 0.2f; //InputZ dampening
    [Range(0, 1f)]
    public float StartAnimTime = 0.3f; //dampens the time of starting the player after input is pressed
    [Range(0, 1f)]
    public float StopAnimTime = 0.15f; //dampens the time of stopping the player after release of input
    private float verticalVel; //Vertical velocity -- currently work in progress
    private Vector3 moveVector; //movement vector -- currently work in progress

    #region Initialization
    // Initialization of variables
    void Start()
    {
    anim = this.GetComponent<Animator>();

    if (anim == null)
    Debug.LogError("We require " + transform.name + " game object to have an animator. This will allow for Foot IK to function");
    }
    // Update is called once per frame

    #endregion
    #region FeetGrounding
    /// <summary>
    /// We are updating the AdjustFeetTarget method and also find the position of each foot inside our Solver Position.
    /// </summary>
    private void FixedUpdate()
    {
    if(enableFeetIk == false) { return; }
    if(anim == null) { return; }
    AdjustFeetTarget(ref rightFootPosition, HumanBodyBones.RightFoot);
    AdjustFeetTarget(ref leftFootPosition, HumanBodyBones.LeftFoot);
    //find and raycast to the ground to find positions
    FeetPositionSolver(rightFootPosition, ref rightFootIkPosition, ref rightFootIkRotation); // handle the solver for right foot
    FeetPositionSolver(leftFootPosition, ref leftFootIkPosition, ref leftFootIkRotation); //handle the solver for the left foot
    }
    private void OnAnimatorIK(int layerIndex)
    {
    if(enableFeetIk == false) { return; }
    if(anim == null) { return; }
    // MovePelvisHeight();
    //right foot ik position and rotation -- utilise the pro features in here
    anim.SetIKPositionWeight(AvatarIKGoal.RightFoot, 1);

    MoveFeetToIkPoint(AvatarIKGoal.RightFoot, rightFootIkPosition, rightFootIkRotation, ref lastRightFootPositionY);
    //left foot ik position and rotation -- utilise the pro features in here
    anim.SetIKPositionWeight(AvatarIKGoal.LeftFoot, 1);

    MoveFeetToIkPoint(AvatarIKGoal.LeftFoot, leftFootIkPosition, leftFootIkRotation, ref lastLeftFootPositionY);
    }
    #endregion
    #region FeetGroundingMethods
    /// <summary>
    /// Moves the feet to ik point.
    /// </summary>
    /// <param name="foot">Foot.</param>
    /// <param name="positionIkHolder">Position ik holder.</param>
    /// <param name="rotationIkHolder">Rotation ik holder.</param>
    /// <param name="lastFootPositionY">Last foot position y.</param>
    void MoveFeetToIkPoint (AvatarIKGoal foot, Vector3 positionIkHolder, Quaternion rotationIkHolder, ref float lastFootPositionY)
    {
    Vector3 targetIkPosition = anim.GetIKPosition(foot);
    if(positionIkHolder != Vector3.zero)
    {
    targetIkPosition = transform.InverseTransformPoint(targetIkPosition);
    positionIkHolder = transform.InverseTransformPoint(positionIkHolder) *feetToIkPositionDistance;
    float yVariable = Mathf.Lerp(lastFootPositionY, positionIkHolder.y, feetToIkPositionSpeed);
    targetIkPosition.y += yVariable;
    lastFootPositionY = yVariable;
    targetIkPosition = transform.TransformPoint(targetIkPosition);
    anim.SetIKRotation(foot, rotationIkHolder);
    }
    anim.SetIKPosition(foot, targetIkPosition);
    }
    /// <summary>
    /// Moves the height of the pelvis.
    /// </summary>
    private void MovePelvisHeight()
    {
    if(rightFootIkPosition == Vector3.zero || leftFootIkPosition == Vector3.zero || lastPelvisPositionY == 0)
    {
    lastPelvisPositionY = anim.bodyPosition.y;
    return;
    }
    float lOffsetPosition = leftFootIkPosition.y - transform.position.y;
    float rOffsetPosition = rightFootIkPosition.y - transform.position.y;
    float totalOffset = (lOffsetPosition < rOffsetPosition) ? lOffsetPosition : rOffsetPosition;
    Vector3 newPelvisPosition = anim.bodyPosition + Vector3.up * totalOffset;
    newPelvisPosition.y = Mathf.Lerp(lastPelvisPositionY, newPelvisPosition.y, pelvisUpAndDownSpeed);
    anim.bodyPosition = newPelvisPosition;
    lastPelvisPositionY = anim.bodyPosition.y;
    }
    /// <summary>
    /// We are locating the Feet position via a Raycast and then Solving
    /// </summary>
    /// <param name="fromSkyPosition">From sky position.</param>
    /// <param name="feetIkPositions">Feet ik positions.</param>
    /// <param name="feetIkRotations">Feet ik rotations.</param>
    private void FeetPositionSolver(Vector3 fromSkyPosition, ref Vector3 feetIkPositions, ref Quaternion feetIkRotations)
    {
    //raycast handling section
    RaycastHit feetOutHit;
    if (showSolverDebug)
    Debug.DrawLine(fromSkyPosition, fromSkyPosition + Vector3.down * (raycastDownDistance + heightFromGroundRaycast), Color.red);
    Debug.DrawLine(fromSkyPosition, fromSkyPosition + Vector3.down * (raycastDownDistance ) + new Vector3 (0.1f ,0.1f ,0.1f ), Color.green);
    if (Physics.Raycast(fromSkyPosition, Vector3.down, out feetOutHit, raycastDownDistance + heightFromGroundRaycast, environmentLayer))
    {
    //finding our feet ik positions from the sky position
    feetIkPositions = fromSkyPosition;
    feetIkPositions.y = feetOutHit.point.y + pelvisOffset;
    feetIkRotations = Quaternion.FromToRotation(Vector3.up, feetOutHit.normal) * transform.rotation;
    return;
    }
    feetIkPositions = Vector3.zero; //it didn't work :(
    }
    /// <summary>
    /// Adjusts the feet target.
    /// </summary>
    /// <param name="feetPositions">Feet positions.</param>
    /// <param name="foot">Foot.</param>
    private void AdjustFeetTarget (ref Vector3 feetPositions, HumanBodyBones foot)
    {
    feetPositions = anim.GetBoneTransform(foot).position;
    feetPositions.y = transform.position.y + heightFromGroundRaycast;
    }
    #endregion

    }
     
  27. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    A better But slower solution to the Groundcheck stuck is to use SphereCastNonAlloc with a radius bigger than the player's collider .
    switchRaysphere is a bool that will switch the raycast from RaycastNonAlloc to SphereCastNonAlloc

    replace in findGroundAndSlope
    if (switchRaysphere) {

    count = Physics.SphereCastNonAlloc(start, SphereGroundCheckradius -0.01f, Vector3.down, Util.Hits, threshold + GroundAndSlopeoffset, Layers.Geometry);
    } else {
    count = Physics.RaycastNonAlloc(start, Vector3.down, Util.Hits, threshold + GroundAndSlopeoffset, Layers.Geometry);

    }
     
    Lay84 likes this.
  28. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    Thank you, however, I am using a Logitech dual action controller the axis is 4 and 3.

    Please note: I am not a coder and will need a little bit more help.

    What script controls the mouse camera movement do I simply copy and paste the code shown in the link?
     
  29. Lay84

    Lay84

    Joined:
    Mar 8, 2014
    Posts:
    32
    on a roll @Rahd, giving Gems to the community and keeping this alive.
     
    Rahd likes this.
  30. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
  31. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    no coding is required
    go to input manager


    mouse x and Y upload_2019-11-25_15-55-20.png
    change it to



    more on this here : https://answers.unity.com/questions/1429429/how-to-use-right-analog-stick-from-xbox-controller.html
    the script you linked add support to both mouse and Gamepad

    i really don't have a Gamepad or use the third cover shooter (mobile) , i can't test. but that should work .
     
    colpolstudios likes this.
  32. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    I did not have to put the name of my controller into the descriptive name, but it works.

    The speed is very slow using this method on its own, how do I increase the speed?
     
  33. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    the Sensitivity option should take care of that 5 rows before the last tab , as you can see it's 0.1 but on the image in black it's 1
     
  34. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    I found that 3 was a good value any higher and the environment can be seen to move.

    Though, it's a little odd that when not aiming the controls for up and down are reversed. With help form my own project I was able to remap the controller keys to my joystick.

    I would also like to add the roll forward but map them to the D-pad Axis. Possibly someone has already done this and would share?

    Thank you Rahad for your help and reply
     
    Rahd likes this.
  35. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    I finally got to playtest the third person scene, I killed all the bad guys it's very hard to do. But when finished I checked the console and have 331 errors "argument is out of range" should I worry about this?
     
  36. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    284
    NahI It's just raycast calls made before the ai completely die. It hasnt hurt mine in any meaningful way. So e of that's just debug stuff.
     
    colpolstudios likes this.
  37. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    Great thanks for the help
     
  38. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    259
    in the beta "RollForward RollBackward RollLeft RollRight " are mapped try to email the dev for a copy of that .
     
  39. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    25
    Hi Rahd, Ill ask for sure.

    For me and my controller, its axis 5 = d-pad left and right and axis 6 = d-pad up and down.

    maybe that info helps?

    To be honest, I'm working on my own project and have not really given the asset the time it needs.

    But form the initial playtest. I will be spending time with this valuable asset.

    Thankyou kind sir for your time and help so far :)
     
    Rahd likes this.