Player turns inplace when clicked on

I am not sure were to look to solve this. Every time I click on my player he rotates. I am not sure when this started. I just noticed it when I added my cinemachine camera. I tried deleting the camera, and disabling the capsule collider. Behavior makes it nearly impossible to hit the enemies. Any Ideas where I should look.

using RPG.Movement;
using RPG.Combat;
using RPG.Core;

using UnityEngine;
using System;

namespace RPG.Control
{
    public class PlayerController : MonoBehaviour
    {

        Mover mover;
        Fighter fighter;
        Health health;
       
        void Start()
        {
            mover = GetComponent<Mover>();
            fighter = GetComponent<Fighter>();
            health = GetComponent<Health>();
        }
        
        void Update()
        {
            if (health.IsDead()) return;
            if (InteractWithCombat()) return;
            if(InteractWithMovement()) return;
        }

        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent<CombatTarget>();
                if (target == null) continue;
                
                if (!fighter.CanAttack(target.gameObject)) continue;
                if (Input.GetMouseButton(0))
                {
                    fighter.Attack(target.gameObject);
                }
                return true;                
            }
            return false;
        }
    private bool InteractWithMovement()
        {
            RaycastHit hit;
            bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
            if (hasHit )
            {
                if (Input.GetMouseButton(0))
                {
                    mover.StartMoveAction(hit.point, 1f);
                }
                return true;
            }
            return false;
        }

        private static Ray GetMouseRay()
        {
            return Camera.main.ScreenPointToRay(Input.mousePosition);
        }
    }
}

![Screenshot 2022-12-18 092000|203x500](upload://oLv2LAoKeEHN0ohGQamlT1V5S41.png)

I think I found what is causing it. I was using 3rd person follow to get some rotation and that caused the bug. Is there any way to use this body with out the bug.

Are you meaning that the camera rotates?

That is exactly how the Cinemachine 3rd Person Follow is supposed to behave, it’s not actually a bug.

I was meaning the player rotates but it is fine I am sure it is just some setting I don’t have right and would need to play with it. If I use the camera setting in the lecture it works fine. I was just trying to get the camera to rotate so that the view was better.

it’s likely, the player rotating behavior is because the NavMeshAgent can never truly get the character to an exact point… for this purpose, we tend to have an acceptance radius to the target…

Try adding this to Mover.Update()

if (navMeshAgent.isStopped == false && navMeshAgent.remainingDistance < 1) navMeshAgent.isStopped = true;

Privacy & Terms