0
我使用var heading = target.position - player.position;
來計算一個Vector3,它顯示了從我的敵人到我的玩家的標題,但顯然當距離不同時速度不同。所以當它真的很近的時候,它會變得非常慢,當它很遠的時候它會變得非常快。有沒有辦法讓它始終保持相同的速度?我使用rigidbody.velocity
順便說一句。速度取決於Unity中的距離?
這是對球員腳本全招:
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public Rigidbody rb;
public bool yaonah = true;
public Transform player;
public float speed = 100;
// Use this for initialization
void Start() {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update() {
if (yaonah) {
StartCoroutine(Wait(2));
}
}
void Move()
{
Debug.Log(rb.velocity);
//Vector3 dir = Random.insideUnitCircle * 5;
var pdir = player.position - transform.position;
rb.velocity = pdir; //Player Direction
Debug.Log("HEY");
Debug.Log(pdir + "PlayerPos");
}
IEnumerator Wait(float waittime)
{
yaonah = false;
Move();
yield return new WaitForSeconds(waittime);
yaonah = true;
}
}
你有更多的代碼w e可以用來使這個學習過程? – ejsd1989