Beispiel #1
0
        private void UpdateMouseAim()
        {
            Ray   ray         = viewCamera.ScreenPointToRay(mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.up * aimHeight);

            if (groundPlane.Raycast(ray, out float rayDistance))
            {
                Vector3 point = ray.GetPoint(rayDistance);
                Debug.DrawLine(ray.origin, point, Color.red);

                aimEvent.Invoke(point);
                detectEvent.Invoke(ray);

                movementController.LookAt(point);
            }
        }
 /// <summary>
 /// Aim the transform towards the direction. Checks if the vector is 0.
 /// </summary>
 /// <param name="aimVec">The direction to aim towards, relative to the right vector</param>
 public void AimToward(Vector3 aimVec)
 {
     if (!Mathf.Approximately(aimVec.sqrMagnitude, 0))
     {
         OnAim.Invoke(aimVec);
         transform.right = aimVec;
     }
 }