Hello everyone, everything good? This is my first post here on the Unity forum and it is also my first big problem which I was unable to solve. Well, I've been learning Unity and C # for a few months now and I'm working on a 2D Zombie project with stealth and a dark environment. I needed to create a field of view for the main character, so I found Sebastian Lague's tutorial, which helped me a lot with the field of view and understanding this system. Code (CSharp): using UnityEngine; using System.Collections; using System.Collections.Generic; public class FieldOfView : MonoBehaviour { public float viewRadius; [Range(0, 360)] public float viewAngle; public LayerMask targetMask; public LayerMask obstacleMask; [HideInInspector] public List<Transform> visibleTargets = new List<Transform>(); void Start() { StartCoroutine("FindTargetWithDelay", 0.2f); } IEnumerator FindTargetWithDelay(float delay) { while (true) { yield return new WaitForSeconds(delay); FindVisibleTargets(); } } //Finds targets inside field of view not blocked by walls void FindVisibleTargets() { visibleTargets.Clear(); //Adds targets in view radius to an array Collider2D[] targetsInViewRadius = Physics2D.OverlapCircleAll(transform.position, viewRadius, targetMask); //For every targetsInViewRadius it checks if they are inside the field of view for (int i = 0; i < targetsInViewRadius.Length; i++) { Transform target = targetsInViewRadius[i].transform; Vector3 dirToTarget = (target.position - transform.position).normalized; if (Vector3.Angle(transform.up, dirToTarget) < viewAngle / 2) { float dstToTarget = Vector3.Distance(transform.position, target.position); //If line draw from object to target is not interrupted by wall, add target to list of visible //targets if (!Physics2D.Raycast(transform.position, dirToTarget, dstToTarget, obstacleMask)) { visibleTargets.Add(target); } } } } public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal) { if (!angleIsGlobal) { angleInDegrees -= transform.eulerAngles.z; } return new Vector3(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), Mathf.Cos(angleInDegrees * Mathf.Deg2Rad), 0); } } Code (CSharp): using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor (typeof (FieldOfView))] public class FieldOfViewEditor : Editor { void OnSceneGUI() { FieldOfView fow = (FieldOfView)target; //Draws view reach Handles.color = Color.black; Handles.DrawWireArc(fow.transform.position, Vector3.forward, Vector3.up, 360, fow.viewRadius); //Draws cone of view Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius); } } And since the game is made for mobile, I'm using a virtual joystick. One joystick to move the character horizontally and vertically, and the other to rotate the weapon. Code (CSharp): using System; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; [RequireComponent(typeof(RectTransform))] public class EasyJoystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler { public RectTransform stick; //stick image; public float returnRate = 15.0F; //default position returning speed; public float dragRadius = 65.0f; //drag radius; public AlphaControll colorAlpha; public event Action<EasyJoystick, Vector2> OnStartJoystickMovement; public event Action<EasyJoystick, Vector2> OnJoystickMovement; public event Action<EasyJoystick> OnEndJoystickMovement; private bool _returnHandle, pressed, isEnabled = true; private RectTransform _canvas; private Vector3 globalStickPos; private Vector2 stickOffset; private CanvasGroup canvasGroup; public Vector2 Coordinates { get { if (stick.anchoredPosition.magnitude < dragRadius) return stick.anchoredPosition / dragRadius; return stick.anchoredPosition.normalized; } } void IPointerDownHandler.OnPointerDown(PointerEventData eventData) { pressed = true; _returnHandle = false; stickOffset = GetJoystickOffset(eventData); stick.anchoredPosition = stickOffset; if (OnStartJoystickMovement != null) OnStartJoystickMovement(this, Coordinates); } void IDragHandler.OnDrag(PointerEventData eventData) { stickOffset = GetJoystickOffset(eventData); stick.anchoredPosition = stickOffset; if (OnJoystickMovement != null) OnJoystickMovement(this, Coordinates); } void IPointerUpHandler.OnPointerUp(PointerEventData eventData) { pressed = false; _returnHandle = true; if (OnEndJoystickMovement != null) OnEndJoystickMovement(this); } private Vector2 GetJoystickOffset(PointerEventData eventData) { if (RectTransformUtility.ScreenPointToWorldPointInRectangle(_canvas, eventData.position, eventData.pressEventCamera, out globalStickPos)) stick.position = globalStickPos; var handleOffset = stick.anchoredPosition; if (handleOffset.magnitude > dragRadius) { handleOffset = handleOffset.normalized * dragRadius; stick.anchoredPosition = handleOffset; } return handleOffset; } private void Start() { canvasGroup = GetComponent ("CanvasGroup") as CanvasGroup; _returnHandle = true; var touchZone = GetComponent("RectTransform") as RectTransform; touchZone.pivot = Vector2.one * 0.5F; stick.transform.SetParent(transform); var curTransform = transform; do { if (curTransform.GetComponent<Canvas>() != null) { _canvas = curTransform.GetComponent("RectTransform") as RectTransform;; break; } curTransform = transform.parent; } while (curTransform != null); } private void FixedUpdate() { if (_returnHandle) if (stick.anchoredPosition.magnitude > Mathf.Epsilon) stick.anchoredPosition -= new Vector2(stick.anchoredPosition.x * returnRate, stick.anchoredPosition.y * returnRate) * Time.deltaTime; else _returnHandle = false; switch(isEnabled) { case true: canvasGroup.alpha = pressed ? colorAlpha.pressedAlpha : colorAlpha.idleAlpha; canvasGroup.interactable = canvasGroup.blocksRaycasts = true; break; case false: canvasGroup.alpha = 0; canvasGroup.interactable = canvasGroup.blocksRaycasts = false; break; } } public Vector2 MoveInput() { return new Vector2 (Coordinates.x, Coordinates.y); } public void Rotate(Transform transformToRotate, float speed) { if(Coordinates != Vector2.zero) transformToRotate.rotation = Quaternion.Slerp (transformToRotate.rotation, Quaternion.LookRotation (new Vector2 (Coordinates.x, Coordinates.y)), speed * Time.deltaTime); } public bool IsPressed() { return pressed; } public void Enable(bool enable) { isEnabled = enable; } } [Serializable] public class AlphaControll { public float idleAlpha = 0.5F, pressedAlpha = 1.0F; } The idea was to use the field of view with the rotation of the right joystick, but I was unable to make it work in any way, I have already changed several parts of the code and I always find myself in the problem of not being able to rotate the Z axis by the joystick. If you guys can help me in any way I really appreciate it, or if need more information, I will be available !