[英]Unity 2d - I want to remove the rotation of the image in a top down game
我想修復代碼,因此在轉換到下一個要修復的點時圖像不會旋轉,但是無法
對寫作錯誤道歉,我不會說英語
[SerializeField] private Transform[] patrolPoints; Transform currentPatrolPoint; int currentPatrolIndex; protected override void Start() { currentPatrolIndex = 0; currentPatrolPoint = patrolPoints[currentPatrolIndex]; base.Start(); } protected override void Update() { transform.Translate(Vector3.up * Time.deltaTime * MySpeed); if (Vector3.Distance(transform.position,currentPatrolPoint.position)<0.1f) { if(currentPatrolIndex+1<patrolPoints.Length) { currentPatrolIndex++; } else { currentPatrolIndex = 0; } currentPatrolPoint = patrolPoints[currentPatrolIndex]; } Vector3 patrolPointDirection = currentPatrolPoint.position - transform.position; float angle = Mathf.Atan2(patrolPointDirection.y, patrolPointDirection.x) * Mathf.Rad2Deg - 90f; Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = Quaternion.RotateTowards(transform.rotation, q,180f); }
如果您不希望它旋轉,請刪除此部分,該部分正在旋轉GameObject:
float angle = Mathf.Atan2(patrolPointDirection.y, patrolPointDirection.x) * Mathf.Rad2Deg - 90f;
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q,180f);
同樣,僅用於transform.rotation的任何變量也可以從代碼中刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.