我的遊戲中的玩家可以懸浮物體並用鼠標在世界xy上移動它們。當他移動時,我怎樣才能讓球員隨球員移動?我怎樣才能使這個對象相對於玩家的位置?
private void levitateObject() {
//Debug.Log("Levitating");
float yAxis = Input.GetAxis("Mouse Y");
float xAxis = Input.GetAxis("Mouse X");
Vector3 frontForce = playerCamera.transform.TransformDirection(Vector3.forward) * (yAxis * 1.5f) ;
Vector3 rightForce = playerCamera.transform.TransformDirection(Vector3.right) * (xAxis * 1.5f);
Vector3 currPos = levitatingObject.transform.position;
Vector3 nextPos = new Vector3 (levitatingObject.transform.position, elevation, levitatingObject.transform.position) + rightForce + frontForce;
levitatingObject.GetComponent <Rigidbody>().velocity = (nextPos - currPos) * 10;
}
我想做類似下面的事情,但後來我的對象根本不動。
Vector3 nextPos = new Vector3 (transform.position.x + (levitatingObject.transform.position.x -transform.position.x) , elevation, transform.position.z + (levitatingObject.transform.position.z -transform.position.z));
是你的意思。你想要一個平滑的對象? – Aizen