【发布时间】:2015-10-09 22:10:14
【问题描述】:
我正在使用var heading = target.position - player.position; 来计算一个 Vector3,它显示了从我的敌人到我的玩家的航向,但显然当距离不同时速度会有所不同。所以当它真的很近时,它会走得很慢,当它很远时,它会走得很快。有没有办法让它一直以相同的速度运行?我正在使用rigidbody.velocity btw。
这是播放器脚本的完整步骤:
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;
}
}
【问题讨论】:
-
你有更多的代码我们可以用来学习吗?
标签: c# unity3d game-physics