Search Unity

Third person cover controller

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

  1. lastwinner123456

    lastwinner123456

    Joined:
    Jan 20, 2019
    Posts:
    8

    and what i need to change in this script ?

    using UnityEngine;
    using UnityEngine.EventSystems;


    namespace CoverShooter
    {
    /// <summary>
    /// Takes player input and transform it to commands to ThirdPersonController.

    [RequireComponent(typeof(CharacterMotor))]
    [RequireComponent(typeof(ThirdPersonController))]
    [RequireComponent(typeof(Actor))]
    public class TopDownInput : MonoBehaviour, ICharacterController
    {

    /// <summary>
    /// Input is ignored when a disabler is active.
    /// </summary>
    [Tooltip("Input is ignored when a disabler is active.")]
    public GameObject Disabler;

    /// <summary>
    /// Marker that is placed on the ground to mark the target the character is aiming at.
    /// </summary>
    [Tooltip("Marker that is placed on the ground to mark the target the character is aiming at.")]
    public GameObject Marker;

    /// <summary>
    /// Should the character walk by default and run, or run by default and sprint when needed.
    /// </summary>
    [Tooltip("Should the character walk by default and run, or run by default and sprint when needed.")]
    public bool WalkByDefault = false;

    /// <summary>
    /// Should the character sprint towards the target instead of relative screen up direction.
    /// </summary>
    [Tooltip("Should the character sprint towards the target instead of relative screen up direction.")]
    public bool SprintTowardsTarget = false;

    /// <summary>
    /// Marker should be enabled and disabled together with this component.
    /// </summary>
    [Tooltip("Marker should be enabled and disabled together with this component.")]
    public bool ManageMarkerVisibility = true;

    /// <summary>
    /// Will the marker be constantly displayed on the ground.
    /// </summary>
    [Tooltip("Will the marker be constantly displayed on the ground.")]
    public bool MarkerAlwaysOnGround = true;

    /// <summary>
    /// Height off the ground the marker is displayed at.
    /// </summary>
    [Tooltip("Height off the ground the marker is displayed at.")]
    public float GroundLift = 0.218f;
    [Tooltip("Maximum time in seconds to wait for a second tap to active rolling.")]
    public float DoubleTapDelay = 0.3f;
    private Actor _actor;
    private CharacterMotor _motor;
    private ThirdPersonController _controller;
    private CharacterInventory _inventory;
    private bool _isAimingFriendly = false;
    private bool _isFireDown;
    private bool _isZoomDown;
    private bool _isSprinting;

    private float _angle;

    private float[] _snapWork = new float[_snaps.Length];
    private static float[] _snaps = new float[] { 0, -45, 45, -90, 90, 135, -135, 180 };
    private float _timeW;
    private float _timeA;
    private float _timeS;
    private float _timeD;
    public Transform crosshairs;
    private float _leftMoveIntensity = 1;
    private float _rightMoveIntensity = 1;
    private float _backMoveIntensity = 1;
    private float _frontMoveIntensity = 1;
    /// <summary>
    /// Update the position under the mouse. Performed after the camera has adjusted it's position.
    /// </summary>
    public void UpdateAfterCamera()
    {
    UpdateTarget();
    }

    private void Awake()
    {
    _controller = GetComponent<ThirdPersonController>();
    _motor = GetComponent<CharacterMotor>();
    _actor = GetComponent<Actor>();
    _controller.WaitForUpdateCall = true;
    _inventory = GetComponent<CharacterInventory>();
    Cursor.visible = false;

    }
    void Start()
    {

    }

    private void OnDisable()
    {
    if (Marker != null && ManageMarkerVisibility)
    Marker.SetActive(false);
    }

    private void Update()
    {


    if (Disabler != null && Disabler.activeSelf)
    return;

    if (Marker != null && ManageMarkerVisibility)
    {
    if (EventSystem.current.IsPointerOverGameObject())
    {
    if (Marker.activeSelf)
    Marker.SetActive(false);
    }
    else if (!Marker.activeSelf)
    Marker.SetActive(true);
    }

    var camera = Camera.main;
    var updateAfterCamera = false;

    if (camera != null)
    {
    var comp = camera.GetComponent<CharacterCamera>();

    if (comp != null)
    {
    updateAfterCamera = true;
    comp.DeferUpdate(this);
    }
    }

    if (!updateAfterCamera)
    UpdateAfterCamera();





    // _controller.LookAt(point);
    // crosshairs.transform.position = point;
    // _controller.AimTargetInput = lookPosition;



    UpdateTarget();

    UpdateMovement();
    UpdateWeapons();
    UpdateReload();
    UpdateRolling();
    UpdateAttack();

    UpdateCrouching();
    UpdateClimbing();



    _controller.ManualUpdate();
    }

    protected virtual void UpdateClimbing()
    {
    if (Input.GetButtonDown("Climb"))
    {
    var direction = Input.GetAxis("Horizontal") * Vector3.right +
    Input.GetAxis("Vertical") * Vector3.forward;

    if (direction.magnitude > float.Epsilon)
    {
    direction = Quaternion.Euler(0, aimAngle, 0) * direction.normalized;

    var cover = _motor.GetClimbableInDirection(direction);

    if (cover != null)
    _controller.InputClimbOrVault(cover);
    }
    }
    }


    protected virtual void UpdateWeapons()
    {
    if (Input.GetKey(KeyCode.Alpha1)) { _motor.InputCancelGrenade(); inputWeapon(0); }
    if (Input.GetKey(KeyCode.Alpha2)) { _motor.InputCancelGrenade(); inputWeapon(1); }
    if (Input.GetKey(KeyCode.Alpha3)) { _motor.InputCancelGrenade(); inputWeapon(2); }
    if (Input.GetKey(KeyCode.Alpha4)) { _motor.InputCancelGrenade(); inputWeapon(3); }
    if (Input.GetKey(KeyCode.Alpha5)) { _motor.InputCancelGrenade(); inputWeapon(4); }
    if (Input.GetKey(KeyCode.Alpha6)) { _motor.InputCancelGrenade(); inputWeapon(5); }
    if (Input.GetKey(KeyCode.Alpha7)) { _motor.InputCancelGrenade(); inputWeapon(6); }
    if (Input.GetKey(KeyCode.Alpha8)) { _motor.InputCancelGrenade(); inputWeapon(7); }
    if (Input.GetKey(KeyCode.Alpha9)) { _motor.InputCancelGrenade(); inputWeapon(8); }
    if (Input.GetKey(KeyCode.Alpha0)) { _motor.InputCancelGrenade(); inputWeapon(9); }



    }


    private int currentWeapon
    {
    get
    {
    if (_inventory == null || !_motor.IsEquipped)
    return 0;

    for (int i = 0; i < _inventory.Weapons.Length; i++)
    if (_inventory.Weapons.IsTheSame(ref _motor.Weapon))
    return i + 1;

    return 0;
    }
    }

    private void inputWeapon(int index)
    {
    if (_inventory == null && index > 0)
    return;

    if (index <= 0 || (_inventory != null && index > _inventory.Weapons.Length))
    _controller.InputUnequip();
    else if (_inventory != null && index <= _inventory.Weapons.Length)
    _controller.InputEquip(_inventory.Weapons[index - 1]);
    }


    protected virtual void UpdateMovement()
    {
    var movement = new CharacterMovement();

    var direction = Input.GetAxis("Horizontal") * Vector3.right +
    Input.GetAxis("Vertical") * Vector3.forward;

    if (WalkByDefault)
    {
    _isSprinting = false;
    movement.Magnitude = 0.5f;

    if (!_isZoomDown && Input.GetButton("Run"))
    movement.Magnitude = 1.0f;
    }
    else
    {
    movement.Magnitude = 1.0f;

    if (_isZoomDown)
    {
    _isSprinting = false;
    movement.Magnitude = 0.5f;
    }
    else
    {
    _isSprinting = Input.GetButton("Run");

    if (_isSprinting)
    movement.Magnitude = 1.0f;
    }
    }

    var camera = Camera.main;
    var lookAngle = 0f;

    if (camera == null || (_isSprinting && SprintTowardsTarget))
    lookAngle = Util.HorizontalAngle(_controller.AimTargetInput - transform.position);
    else
    lookAngle = Util.HorizontalAngle(camera.transform.forward);

    if (direction.magnitude > float.Epsilon)
    movement.Direction = Quaternion.Euler(0, lookAngle, 0) * direction.normalized;

    _controller.MovementInput = movement;
    }
    protected virtual void UpdateAttack()
    {
    if (Input.GetButtonDown("Fire"))
    _controller.FireInput = true;

    if (Input.GetButtonUp("Fire"))
    _controller.FireInput = false;

    if (Input.GetButtonDown("Melee"))
    _controller.InputMelee();

    if (Input.GetButtonDown("Zoom"))
    _controller.ZoomInput = true;

    if (Input.GetButtonUp("Zoom"))
    _controller.ZoomInput = false;

    if (Input.GetButtonDown("Block"))
    _controller.BlockInput = true;

    if (Input.GetButtonUp("Block"))
    _controller.BlockInput = false;

    if (_controller.IsZooming)
    {
    if (Input.GetButtonDown("Scope"))
    _controller.ScopeInput = !_controller.ScopeInput;
    }
    else
    _controller.ScopeInput = false;
    }
    protected virtual void UpdateFire()
    {
    if (Input.GetButtonDown("Fire") && !EventSystem.current.IsPointerOverGameObject())
    _isFireDown = true;

    if (Input.GetButtonUp("Fire"))
    _isFireDown = false;

    if (Input.GetButtonDown("Zoom") && !EventSystem.current.IsPointerOverGameObject())
    _isZoomDown = true;

    if (Input.GetButtonUp("Block"))
    _controller.BlockInput = false;

    if (Input.GetButtonDown("Melee"))
    _motor.InputMelee();

    if (_isFireDown && !_isAimingFriendly)
    _controller.FireInput = true;
    else
    _controller.FireInput = false;

    _controller.ZoomInput = _isZoomDown;
    }
    protected virtual void UpdateCrouching()
    {
    if (Input.GetButton("Crouch"))
    _controller.InputCrouch();
    }
    protected virtual void UpdateReload()
    {
    if (Input.GetButton("Reload"))
    _controller.InputReload();
    }

    protected virtual void UpdateRolling()
    {
    if (_timeW > 0) _timeW -= Time.deltaTime;
    if (_timeA > 0) _timeA -= Time.deltaTime;
    if (_timeS > 0) _timeS -= Time.deltaTime;
    if (_timeD > 0) _timeD -= Time.deltaTime;

    if (Input.GetButtonDown("RollForward"))
    {
    if (_timeW > float.Epsilon)
    {
    var cover = _motor.GetClimbambleInDirection(aimAngle);

    if (cover != null)
    _controller.InputClimbOrVault(cover);
    else
    roll(Vector3.forward);
    }
    else
    _timeW = DoubleTapDelay;
    }

    if (Input.GetButtonDown("RollLeft"))
    {
    if (_timeA > float.Epsilon)
    {
    var cover = _motor.GetClimbambleInDirection(aimAngle - 90);

    if (cover != null)
    _controller.InputClimbOrVault(cover);
    else
    roll(-Vector3.right);
    }
    else
    _timeA = DoubleTapDelay;
    }

    if (Input.GetButtonDown("RollBackward"))
    {
    if (_timeS > float.Epsilon)
    {
    var cover = _motor.GetClimbambleInDirection(aimAngle + 180);

    if (cover != null)
    _controller.InputClimbOrVault(cover);
    else
    roll(-Vector3.forward);
    }
    else
    _timeS = DoubleTapDelay;
    }

    if (Input.GetButtonDown("RollRight"))
    {
    if (_timeD > float.Epsilon)
    {
    var cover = _motor.GetClimbambleInDirection(aimAngle + 90);

    if (cover != null)
    _controller.InputClimbOrVault(cover);
    else
    roll(Vector3.right);
    }
    else
    _timeD = DoubleTapDelay;
    }
    }

    protected virtual void UpdateTarget()
    {
    if (_controller == null || (!_isFireDown && EventSystem.current.IsPointerOverGameObject()))
    return;

    var camera = Camera.main;
    if (camera == null) return;

    var mouse = Input.mousePosition;
    mouse.z = camera.nearClipPlane;

    var near = camera.ScreenToWorldPoint(mouse);

    mouse.z = camera.farClipPlane;
    var far = camera.ScreenToWorldPoint(mouse);

    Vector3 lookNormal;
    var lookPosition = Util.GetClosestHitIgnoreSide(near, far, 1, _actor.Side, out lookNormal);
    var groundPosition = lookPosition;

    var targetActor = AIUtil.FindClosestActor(lookPosition, 0.7f, _actor);

    // if (targetActor != null 0.7f, _actor)
    // groundPosition = targetActor.transform.position;

    var ground = _actor.transform.position.y + 1.5f;

    if (_motor.ActiveWeapon.Gun != null)
    ground = _motor.GunOrigin.y;

    var displayMarkerOnGround = MarkerAlwaysOnGround || targetActor != null;


    if (targetActor != null && targetActor.Side != _actor.Side)
    lookPosition.y = Vector3.Lerp(targetActor.transform.position, targetActor.TopPosition, 0.75f).y;
    else if (lookPosition.y > _actor.transform.position.y - 0.5f && lookPosition.y <= ground)
    {
    var plane = new Plane(Vector3.up, -ground);
    var direction = (far - near).normalized;
    var ray = new Ray(near, direction);

    float enter;
    if (plane.Raycast(ray, out enter))
    {
    lookPosition = near + direction * enter;
    displayMarkerOnGround = MarkerAlwaysOnGround;
    }
    }

    if (Marker != null)
    {
    Vector3 up;

    if (displayMarkerOnGround)
    {
    up = targetActor == null ? lookNormal : Vector3.up;
    Marker.transform.position = groundPosition + GroundLift * up;
    }
    else
    {
    Marker.transform.position = lookPosition;
    up = -_motor.GunDirection;
    }

    Vector3 right;

    if (Vector3.Distance(up, Vector3.forward) > 0.01f)
    right = Vector3.right;
    else
    right = Vector3.Cross(up, Vector3.forward);

    var forward = Vector3.Cross(right, up);

    Marker.transform.LookAt(Marker.transform.position + forward, up);
    }

    {
    var axis = Util.HorizontalAngle(camera.transform.forward);
    var top = _actor.transform.position + 1.5f * Vector3.up;
    var vector = lookPosition - top;
    vector.y = 0;

    var angle = Util.HorizontalAngle(vector);

    var distance = vector.magnitude;

    if (distance < 2 && distance > float.Epsilon)
    {
    var height = lookPosition.y;

    if (distance < 1)
    Util.LerpAngle(ref _angle, angle, distance * 2);
    else
    _angle = angle;

    lookPosition = top + Util.HorizontalVector(_angle) * 2;
    lookPosition.y = height;
    }
    else
    _angle = angle;
    }

    {
    var axis = Util.HorizontalAngle(camera.transform.forward);

    for (int i = 0; i < _snaps.Length; i++)
    _snapWork = Mathf.Abs(Mathf.DeltaAngle(axis + _snaps, _angle));

    var angle = axis;

    for (int i = 0; i < _snaps.Length; i++)
    {
    var isOk = true;

    for (int j = i + 1; j < _snaps.Length; j++)
    if (_snapWork[j] < _snapWork)
    {
    isOk = false;
    break;
    }

    if (isOk)
    {
    angle = axis + _snaps;
    break;
    }
    }

    _controller.BodyTargetInput = _actor.transform.position + Util.HorizontalVector(angle) * 10;
    }

    _controller.AimTargetInput = lookPosition;

    if (!_isSprinting && Mathf.Abs(Mathf.DeltaAngle(Util.HorizontalAngle(_motor.transform.forward), Util.HorizontalAngle(_controller.BodyTargetInput - _motor.transform.position))) > 90)
    _motor.InputPossibleImmediateTurn();
    }
    private Vector3 getMovementDirection(Vector3 local)
    {
    var forward = _controller.BodyTargetInput - transform.position;
    forward.y = 0;
    forward.Normalize();

    float angle;

    if (_motor.IsInCover)
    {
    angle = Util.HorizontalAngle(forward);

    if (_motor.Cover.IsLeft(angle, 45))
    angle = Util.HorizontalAngle(_motor.Cover.Left);
    else if (_motor.Cover.IsRight(angle, 45))
    angle = Util.HorizontalAngle(_motor.Cover.Right);
    else if (_motor.Cover.IsBack(angle, 45))
    angle = Util.HorizontalAngle(-_motor.Cover.Forward);
    else
    angle = Util.HorizontalAngle(_motor.Cover.Forward);

    forward = Util.HorizontalVector(angle);
    }
    else
    angle = Util.HorizontalAngle(forward);

    var right = Vector3.Cross(Vector3.up, forward);

    Util.Lerp(ref _leftMoveIntensity, _motor.IsFreeToMove(-right) ? 1.0f : 0.0f, 4);
    Util.Lerp(ref _rightMoveIntensity, _motor.IsFreeToMove(right) ? 1.0f : 0.0f, 4);
    Util.Lerp(ref _backMoveIntensity, _motor.IsFreeToMove(-forward) ? 1.0f : 0.0f, 4);
    Util.Lerp(ref _frontMoveIntensity, _motor.IsFreeToMove(forward) ? 1.0f : 0.0f, 4);

    if (local.x < -float.Epsilon) local.x *= _leftMoveIntensity;
    if (local.x > float.Epsilon) local.x *= _rightMoveIntensity;
    if (local.z < -float.Epsilon) local.z *= _backMoveIntensity;
    if (local.z > float.Epsilon) local.z *= _frontMoveIntensity;

    return Quaternion.Euler(0, angle, 0) * local;
    }

    private void roll(Vector3 local)
    {
    var direction = getMovementDirection(local);

    if (direction.sqrMagnitude > float.Epsilon)
    _controller.InputRoll(Util.HorizontalAngle(direction));
    }
    private float aimAngle
    {
    get { return Util.HorizontalAngle(_controller.BodyTargetInput - transform.position); }
    }
    }

    }
     
  2. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Hi, any idea why the shotgun isn't showing a crosshair? I've selected weapon type as shotgun and chosen the same crosshair as the rifle, but it doesn't show?
     
  3. Anhella

    Anhella

    Joined:
    Nov 18, 2013
    Posts:
    67
    good day
    how can I get my character to face the direction I put him in? I tried a script from off this forum but it did not work. My character still faces the wrong direction. Please help
    thanks in advance
     
  4. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Thanks for that, I did change it to use custom and found the checkbox. Works fine now. Not sure why the deafult one wasn't showing though but not an issue.

    Another question, does anyone know why when moving on terrain I only shoot when grounded? I'd like to make it so I can fire even if there are slopes and I lose contact temporarily with the ground.
     
    Last edited: Dec 31, 2019
  5. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    when jumping against a cover or an object the player will get stuck in a jumping loop since he is grounded and _isIntendingToJump
    so the jump clip will keep playing over and over
    so to fix this open the Motor script , head to InputEndJump() and add in it _isIntendingToJump = false;
    this will stop the loop in updateVertical() :

    if (_isGrounded && _ignoreJumpTimer <= float.Epsilon)
    {
    if (_isIntendingToJump
     
  6. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Thanks for the reply, I tried this but it still doesn't fix the issue. Also Happy New year to everyone.

    Perhaps I should clarify, the issue happens when I'm running on terrain, specifically downhill. The player is unable to shoot until they come to a standstill.

    I've just tested more and this happens when running down slopes as well, so it's not specific to terrain. Also I can shoot while running either across flat terrain or uphill, just not downhill.

    I'd appreciate any other suggestions. Perhaps groundThreshold needs adjusting?

    I'll try adding autorun and log the values of wantsToFire and can fire etc. Has anyone else experienced this issue?

    [Edit] I've fixed this by adding a Boolean to 3rd person input is shooting, and then using thst in the UpdateFire function in the motor e.g. if can shoot or is shooting. Bit of a hack and I'm not sure if this is default behaviour, but no longer a problem.
     
    Last edited: Jan 1, 2020
  7. 3CHO12

    3CHO12

    Joined:
    Apr 4, 2015
    Posts:
    18
    Hey there, tried to find answer in forum and watch videos, sorry I know this is basic and I must have missed something...Why cant I adjust hand position for holding guns like in video, my character(humanoid) or on original cowboy?

    UNITY 2019.1.14f1 TPC 1.6.2
     
  8. lastwinner123456

    lastwinner123456

    Joined:
    Jan 20, 2019
    Posts:
    8
    I have some problems with climb.Animation is playing but player can't climb platforms.
     
    Lagunajam likes this.
  9. Anhella

    Anhella

    Joined:
    Nov 18, 2013
    Posts:
    67
    Good day

    go to the rifle gun script and under the gun script select custom crosshair in the first slot which is zero, click the radio button and add your new crosshair. and make sure use custom crosshair is check its right above the custom crosshair. hope this help.
     
    Last edited: Mar 1, 2020
  10. lastwinner123456

    lastwinner123456

    Joined:
    Jan 20, 2019
    Posts:
    8
    Hi guys,how to make a random waypoints?
     
  11. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324

    For any terrain issues i think this is the modification i have done to the ground check
    And the slop angle do help too mine is set to 55 or 77.
     
  12. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    Hello everyone and happy new year. Im seeking for a reference in this thread to any AI improvement we can make. My main problem is that AI often get stuck running in rock cavity and directly into a wall instead of normally going arround stuff. What can be the cause of this if any and what can be done to improve AI pathing solution ? not sure if the AI rely purely on "position" given by the script of if they actually use navmesh positionning too !?

    At t he beginning of this asset, i bought A*Star in a hope to get good AI pathing, but never really understand what I needed to do with it... AI is really not my thing apparently.

    Any help is appreciated and I could also consider hiring a specialist at reasonable cost.
     
  13. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Rahd is there any solid way to improve the movement? player gets stuck on EVERYTHING, pretty much needs a very flat surface to move around on. like the collider used doesn't slide at all. is there a way to change the capsule collider to a character controller collider? or something?
     
  14. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    try to stick a zero friction physics material to the default physics settings
     
  15. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    most the Ai problems is navmesh holes or Places where the ai is not grounded , best way to solve this is have multiple Raycasting around the player or Ai . to me it's very expensive . so i just place the ai in camps like flat planes . and make them never leave that flat surface .
     
    satchell likes this.
  16. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Does anyone know how to rotate the third person camera to a specific gameobject?

    It seems the camera can only be moved by setting it's horizontal and vertical angle, and it's difficult to know if this should be calculated from the camera, the player or thé gun particularly in the vertical/y axis.

    If anyone has an example of how to solve this I'd appreciate it.

    This is for aim assist. I can't get this working to the level that I want, and may even use another controller if this can't be done.
     
    Last edited: Jan 13, 2020
  17. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    If its for aim assist, why not have a outside script rotate the character? The camera should follow, i believe all the camera direction logic is on the player, in the input script.
     
  18. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    flat area... problem is im outsite using unity terrain so there are not much flat area and I can't control where they decide to flee. The problem is is them trying to flee and getting stuck in small area (like between two rock, where navmesh finish with thin triangle). Maybe i should increase "padding" or navmesh agent size but it render small passage unwalkable (unless we can paint manually!?). I would tend to code something that look if an agent is not moving at least a certain distance during X sec, get a new point. But i dont know how to call that routine correctly and cpu-wise friendly. Navmesh sorcery is a little weird, any tool to manually paint the walking path... it would be so much easier if we can do that our self instead of unity's logic.

    It look like AI only draw a straight line between starting position and the fleeing point without checking if that line is actually blocked by something. It could be good to cast 1 ray to check next point position for something, but wouldn't know how to actually go around stuff procedural.

    I also notice that sometime AI end up in the air floating...

    If i may ask another question, when tracing waypoint the point automatically detect "collision" but it's annoying how it detect "trigger" and other object it should not and my waypoint often endup being in the air. Would be great to control the layermask for that editor feature, you know where to locate that ???
     
  19. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Increasing agent radius should work for some of your issues. Th AI should not end up in the air, is the nav mesh in the air? The the ground or anything else the ai could walk on dynamic in any way? Have you modified the map and havent rebaked the navmesh? When baking navmesh, is the link jumping thing turned on?
     
  20. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Can we have a confirmation from the dev if this asset is now an AbandonWare ?

    I know some guys like Rahd are very active here and I'm really grateful !!! :)
     
    Jerome_V, redoxoder and Lay84 like this.
  21. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    I also second the gratitude to Raid. You've helped me handle many issues already, and if it wasnt for you I'd have jumped ship a year ago.
     
    Last edited: Jan 14, 2020
  22. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    I think I've solved aim assist. So when it's active, I set a boolean and then return out of updateCamera in third person input if active.

    While it's active i also set bodytargetinput and camera horizontal/vertical, and call update position and vertical melee angle.

    Its working quite well now.
     
    Last edited: Jan 14, 2020
  23. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Rahd, ive, frankensteined the scripts haha, ive replaced about 1/4 with playmaker logic, and everything is going well. But i have a odd thing, i havent delved too far into, but i find it puzzling atm, if i make a character, player or npc. Then change their mesh renderer, The animations stop working. I believe, reseting the motor script fixes but still testing. Any thoughts on that?
     
  24. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Rahd, I made a couple AI, but they lose sight every update, then gain sight again right away. But its like they get the target, move towards, then lose sight, return to idle, ect ect. Every few seconds, If its only 1 AI, they seem to work fine.
     
  25. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    Hi Everyone, was asked for more mobile stuff.



    Here's the Toggle Handler
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. namespace UnityStandardAssets.CrossPlatformInput
    7. {
    8.  
    9.     public class ToggleHandler : MonoBehaviour
    10.     {
    11.         public string Name;
    12.         private Toggle m_MyToggle;
    13.         // Start is called before the first frame update
    14.         void Start()
    15.         {
    16.             m_MyToggle = GetComponent<Toggle>();
    17.         }
    18.  
    19.         public void SetChangeState()
    20.         {
    21.             if (m_MyToggle.isOn)
    22.             {
    23.                 CrossPlatformInputManager.SetButtonDown(Name);
    24.             }
    25.             if (!m_MyToggle.isOn)
    26.             {
    27.                 CrossPlatformInputManager.SetButtonUp(Name);
    28.             }
    29.         }
    30.     }
    31. }
    32.  
     
    Lay84 and Rahd like this.
  26. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    NM Rahd, Im a moron, apparently the player was on a different Layer
     
  27. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    no , it's the model . every character needs to be rigged to bones , and changing the mesh will lose the rig information , look up the dev's tuto on how to replace characters
     
  28. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    you know what would cause AI to search for cover constantly? AI is getting stuck in-between covers, switching to each cover constantly
     
  29. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    to which is has to be something environmental. if I take the AI from the Demo and put them into my scene, they screw up. but if I take the building from the demo scene and put that into my scene, all the AI seem fine using it. yet with the Areas im building they get screwed up
     
  30. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    no, at first i though that maybe some GUI box could be problematic because it also create trouble with raycasting in editor for the waypoint but havent found any object causing this. navmesh is build on a terrain. Maybe i should reduce the amount of navigation static object. Question, if a "rock" is NOT set to navigation static, will it still count as a obstacle and just prevent the baker to use the object as a walkable surface ?

    ill try rebaking and see if it work.
     
  31. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    ai need cover and search area, without them they go wacko
     
  32. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Anyone have a few tips for setting up cover? Its insanely frustrating. Sometimes it seems to work fine other times the player goes in cover for half a sec then pops out, and as far as i can tell. I set up both covers the same...
     
  33. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    As above I have a basic system for auto aim, or aim assist in place.

    Does anyone have another way of doing this, as its still not up to the standard I'm looking for?

    I'd also be interested in how you're handling auto fire on target. Obviously if I get aim assist working nicely it should be easy with a raycast, but I don't mind manually moving the crosshair to support a different system.
     
    satchell likes this.
  34. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    Question: Is there a tutorial using the free snaps prototype office and third person cover shooter?

    If there is one please post a link.

    thankyou
     
  35. redoxoder

    redoxoder

    Joined:
    May 11, 2013
    Posts:
    74
    hi
    do the asset is abandonned form the dev ???
    no news from EduardasFunka
     
  36. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Unofficially idk, but I believe so, but there are a couple dedicated ppl that seem to work on it and help ppl.
     
  37. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    I've just updated to unity version 2019.2.19f and downloaded the asset into a new project, however, the terrain is now a purple color. How do I fix this?
     
  38. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    Hope this helps...
    Capture.PNG
     
    Rahd and colpolstudios like this.
  39. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    Snaps, not that I am aware of. But maybe have a look at the videos on his YouTube channel. I think they're a good start if you haven't already gone through them.
     
  40. Gege256

    Gege256

    Joined:
    Sep 28, 2015
    Posts:
    9
    Hello

    I m setting up a new prototype with this TP cover controller and while everything works fine with the original cowboy in my scene, when i use my own character everything works except that i can t aim vertically, input reading is fine and camera goes down & up as expected but aiming arms won t adjust vertically; any idea which paremeter i may have forgotten ?In case it matters my test is done aiming with a pistol.
     
  41. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    satchell likes this.
  42. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    I am using the free RPG FPS game assets industrial mostly for the road. When on the elevated sections the character slides down the hill when there is no input.

    Is there a way to stop this?
     
    Last edited: Jan 31, 2020
  43. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Reset the motor script, i find helps
     
  44. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Anybody is using the Brain graph functionality of the beta version available on his GitHub?
     
  45. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    319
    I tried to but I had that unity bug where it would infinity reimport until you run out of memory. Havnt tried since. I'll try again when I get home
     
  46. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    ok cool. I`m using it....or trying to and wanted to exchange a bit on how to create to brains. Working with logic graphs or trees require a different approach.

    There`s missing few functionalities to manipulate the tree like to recenter the screen and cut&paste nodes or subtrees but the rest seems to be working ok tho.
     
  47. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    Hello Everyone, here's a weapon pickup video with script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace CoverShooter
    6. {
    7.  
    8.     public class ItemToPickup : MonoBehaviour
    9.     {
    10.         public CharacterInventory cI;
    11.         public WeaponDescription weapon;
    12.         public int inventoryPlace;
    13.         private void OnTriggerEnter(Collider other)
    14.         {
    15.             if (other.tag == "Player")
    16.             {
    17.                 Destroy(gameObject);
    18.                 cI.Weapons[inventoryPlace] = weapon;
    19.             }
    20.         }
    21.     }
    22.  
    23. }
     
  48. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    this is nice .maybe this will make it better.

    So I have great news for you all .

    Inventory-Pro is now open source, and now I can share some of my scripts to use it with the cover shooter

    https://github.com/devdogio/Inventory-Pro

    so here is some help:
    first, import the inventory pro to another copy of your project.

    open the unity scene of your cover shooter, head to the example unity scene of inventory pro grab it and put it in the hierarchy menu.
    grab all the UI components of inventory pro to the cover scene, and place the scripts in the player of inventory pro into the player of cover shooter. you might miss some components keep the scene unloaded just in case.

    now you make a script that will communicate with the inventory pro.
    PS:
    the inventory pro system is a very old yet powerful asset that has a lot of scripts but well documented and the dev updated the assets a lot like a lot !!!.
    so don't expect me to explain everything in one post and I'm still learning too. will keep helping if you ask.

    here is example scripts and explanations :


    Item in the UI is defined as ItemCollectionSlotUI , this hold most of the information you need like the item itself (InventoryItemBase) and other UI operations.

    CharacterUI hold the items and most events like equipping and unequip .
    InventoryPlayer Holds the inventorywindows , bars like skills and health ...

    InventoryPlayer is kinda the main engine , but in this example i will use CharacterUI for easy examples .
    so using those 2 we can make a script that will notifiy te cover shooter of any items being added or removed :

    public CharacterUI characterUI; // this one is a script on the player from inventory pro .


    Code (CSharp):
    1. // we add   events to handle the items being added or removed .
    2. private void Awake()
    3.         {
    4.           characterUI =GetComponent<CharacterUI>();
    5.        
    6.                 characterUI.OnAddedItem+= CharacterUI_ItemEquipped;
    7.               characterUI.OnRemovedItem += CharacterUI_ItemunEquipped;
    8.             }
    9.  
    10.  
    11.     private void CharacterUI_ItemEquipped(IEnumerable<InventoryItemBase> items, uint amount, bool cameFromCollection)
    12.         {
    13. //here i made  equippable  category with ID =4 as Gun , but each gun has it's own sub id .
    14.  
    15. var equippable = items.FirstOrDefault() as EquippableInventoryItem;
    16.             if (equippable != null)
    17.             {
    18.                 switch (equippable.category.ID) {
    19.                 case 4:
    20.                     Debug.Log ("Gunadded " + equippable.name);
    21.                     break;
    22.                 }
    23.             }
    24.  
    25.  
    26. }
    27.  
    28.  
    29. private void CharacterUI_ItemunEquipped(InventoryItemBase item, uint ID,uint Slot ,uint amount)
    30.         {
    31. if (item != null)
    32.             {
    33.                 switch (item.category.ID) {
    34.                 case 4:
    35.                     Debug.Log ("Gunremoved " + item.name);
    36.                     break;
    37.                 }
    38.  
    39.  
    40.  
    41. }


    to add more to this example i went into cover shooter script WeaponDescription and added public int ID .
    after I changed the CharacterInventory like this :
    //added
    [Tooltip("All the weapons belonging in the Database.")]
    public List<WeaponDescription> WeaponsDatabase;
    //and changed Weapons array to List for easy add and remove.
    public List<WeaponDescription> Weapons;

    Fill WeaponsDatabase with all of the guns you have in your game.
    and we gonna use the example I just put to check the item that was equipped or unequipped and remove or add it to the cover shooter inventory script.
    like this :


    Code (CSharp):
    1. //we add the Awake as the other example for events
    2. private void Awake()
    3.         {
    4.           characterUI =GetComponent<CharacterUI>();
    5.        
    6.                 characterUI.OnAddedItem+= CharacterUI_ItemEquipped;
    7.               characterUI.OnRemovedItem += CharacterUI_ItemunEquipped;
    8.             }
    9.  
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16. // To add
    17. private void CharacterUI_ItemEquipped(IEnumerable<InventoryItemBase> items, uint amount, bool cameFromCollection)
    18.         {
    19.             var equippable = items.FirstOrDefault() as EquippableInventoryItem;
    20.             if (equippable != null)
    21.             {
    22.                 foreach (WeaponDescription Gun in WeaponsDatabase) {
    23.                     if (Gun.ID == equippable.ID ) {
    24.                         Weapons.add (Gun );
    25.                     }
    26.                 }
    27.             }
    28.         }
    29. //to remove
    30. private void CharacterUI_ItemunEquipped(InventoryItemBase item, uint ID,uint Slot ,uint amount)
    31.         {
    32. var equippable = items.FirstOrDefault() as EquippableInventoryItem;
    33.             if (equippable != null)
    34.             {
    35.                 foreach (WeaponDescription Gun in WeaponsDatabase) {
    36.                     if (Gun.ID == equippable.ID ) {
    37.                         Weapons.remove(Gun );
    38.                     }
    39.                 }
    40.             }
    41.         }
    the inventory pro has a lot of features , i stopped using CharacterUI and moved into using the
    ItemCollectionSlotUI and InventoryPlayer to fill the stats and the guns slots for my game .
    this is more complex but it offers a better control over what you can add and not add , Stats and ammo .. etc .

    example of ammo check

    public void Checkammo() {

    foreach (var stat in ActiveSlot.Item.item.stats) {
    if (stat.stat.name == "BulletsLoaded") {
    LoadedBullets=stat.intValue ;
    stat.intValue = LoadedBullets;
    break;
    }
    }

    }
    example of looking for ammo count in inventory :
    // Bullets have ids for each type and each gun has an ammo id to match that
    public Devdog.InventoryPro. ItemCollectionBase Inventory;
    BulletInventory = (int) Inventory.GetItemCount (gunscript.Bullettouse.ID);

    Ids , Stats and categories are created with the item editor of inventory pro .
    look up tuto videos for more info .

    please work on these assets here is some docs and more examples for stats and buy and sell .. etc
    https://inventory-pro-docs.readthedocs.io/en/latest/
    good luck and share what you have done ;) if you can.

    inventory pro is used in major titles and supports a lot of other assets like Quest System pro and that one is open source and made by the same guys of inventory pro .

    https://github.com/devdogio/Quest-System-Pro
    I will dig more into it and see how it will work with cover shooter .

    I know the movement in cover shooter is a bit troublesome and not smooth .
    I'm still looking into ways to use the navmesh with the player or animator.matchtarget to make it better still no clue. let me know if you managed to do this or have plans for it @EduardasFunka
     
    Last edited: Feb 15, 2020
    satchell likes this.
  49. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    Hi satchell, great work and I've subscribed to you.

    unfortunately, I am not a coder, but this seems quite manageable. I use playmaker and have yet to really look into the scripts used for the asset. How much of the functionally is public I wonder?
     
    satchell likes this.
  50. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    After scouring through most of the Character Scripts it does seem that most are public do to all the cross script references. The tricky part is following the breadcrumbs to find the source of the public field, lol.