Cant move a player after hitting the target

hey im at RPG Core Combat Creator: Learn Intermediate Unity C# lecture 28 and im pretty sure my scripts(checked on github) and other stuff i same as in the course but if i hit the target then cant move no more.
Player has mover, player controller, fight script attached all its good probably so im stuck

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

namespace RPG.Movement
{
    public class Mover : MonoBehaviour
    {
        [SerializeField]
        private Transform target;

        private NavMeshAgent navMeshAgent;

        private void Start()
        {
            navMeshAgent = GetComponent<NavMeshAgent>();
        }

        void Update()
        {
            UpdateAnimator();

        }

        public void Stop()
        {
            navMeshAgent.isStopped= true;
        }

        public void MoveTo(Vector3 destination)
        {
            navMeshAgent.destination = destination;
            navMeshAgent.isStopped = false;
        }

        private void UpdateAnimator()
        {
            Vector3 velocity = navMeshAgent.velocity;
            Vector3 localVelocity = transform.InverseTransformDirection(velocity);
            float speed = localVelocity.z;
            GetComponent<Animator>().SetFloat("forwardSpeed", speed);
        }

    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
using System;
using RPG.Combat;

namespace RPG.Control
{
    public class PlayerController : MonoBehaviour
    {

        void Start()
        {

        }


        void Update()
        {
            if(InteractWithCombat()) return;
            if(InteractWithMovement()) return;
            //print("Nothing to do");
        }

        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent<CombatTarget>();
                if (target == null) continue;

                if(Input.GetMouseButtonDown(0))
                {
                    GetComponent<Fighter>().Attack(target);
                }
                return true;
            }
            return false;
        }

        private bool InteractWithMovement()
        {          
            RaycastHit hit;
            bool hasHit = Physics.Raycast(GetMouseRay(), out hit);

            if (hasHit)
            {
                if(Input.GetMouseButtonDown(0))
                {
                    GetComponent<Mover>().MoveTo(hit.point);
                }
                return true;
            }
            return false;
        }

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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
using static UnityEngine.GraphicsBuffer;

namespace RPG.Combat
{
    public class Fighter : MonoBehaviour
    {
        Transform _target;
        [SerializeField]
        float _weaponRange = 2f;

        private void Update()
        {
            if (_target == null) return;

            bool isInRange = Vector3.Distance(transform.position, _target.position) < _weaponRange;

            if(_target != null && !isInRange)
            {
                GetComponent<Mover>().MoveTo(_target.position);
            }
            else
            {
                GetComponent<Mover>().Stop();
            }
        }

        public void Attack(CombatTarget combatTarget)
        {
            _target = combatTarget.transform;
        }
    }
}

This will be covered over the next several lectures. :slight_smile:

Oh excellent, lecturer could so i thought i did smth wrong

Privacy & Terms