Search Unity

Third person cover controller

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

  1. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270
    you need to change the cancel distance on the touch aiming script , lower means a less distance to fire .
    i hope this helps , for the aim you can play with the gun values and the aim error on the motor or mobile controller i think . i changed the aiming script to something else . you can change the fire precision to have a larger auto aim angle
     
  2. lastwinner123456

    lastwinner123456

    Joined:
    Jan 20, 2019
    Posts:
    6

    in this video i put marker in fiid in inspector but marker not worked

    in this video marker don't keep up with the cursor
     
  3. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270
    ahh you're using the Top down one not mobile
    try the double tab delay on the marker script
    not sure about the first video , i will download a fresh project with the topdown and test it more.
    i think the asset is double click to keep up with marker , you gonna have to change the scripts i think .
     
  4. lastwinner123456

    lastwinner123456

    Joined:
    Jan 20, 2019
    Posts:
    6

    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); }
    }
    }

    }
     
  5. 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?
     
  6. dnaster

    dnaster

    Joined:
    Nov 18, 2013
    Posts:
    32
    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
     
  7. 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
  8. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270
    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
     
  9. 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
  10. 3CHO12

    3CHO12

    Joined:
    Apr 4, 2015
    Posts:
    11
    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
     
  11. lastwinner123456

    lastwinner123456

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

    dnaster

    Joined:
    Nov 18, 2013
    Posts:
    32
    ood 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.
     
  13. lastwinner123456

    lastwinner123456

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

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270

    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.
     
  15. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    185
    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.
     
  16. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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?
     
  17. Rahd

    Rahd

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

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270
    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.
  19. 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
  20. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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.
     
  21. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    185
    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 ???
     
  22. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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?
     
  23. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    267
    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 !!! :)
     
    Lay84 likes this.
  24. 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
  25. 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
  26. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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?
     
  27. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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.
     
  28. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    82
    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.  
     
    Rahd likes this.
  29. p_hergott

    p_hergott

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

    Rahd

    Joined:
    May 30, 2014
    Posts:
    270
    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
     
  31. p_hergott

    p_hergott

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

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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
     
  33. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    185
    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.
     
  34. Unplug

    Unplug

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

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    308
    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...
     
  36. 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.
  37. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    26
    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
     
  38. redoxoder

    redoxoder

    Joined:
    May 11, 2013
    Posts:
    67
    hi
    do the asset is abandonned form the dev ???
    no news from EduardasFunka
     
unityunity