我有具有面部(頭部)和身體的玩家角色。
Player - Head
- Body
目前我附加到的源代碼player是這樣的,
public void moveForward(){
Debug.Log("move forward");
speed = 40;
Debug.Log("Head Rotation y:" head.transform.localEulerAngles.y); // For example it shows 30
float y_rotation = head.transform.localEulerAngles.y;
this.transform.Translate(0,0,speed/50);// It goes to the player direction, how can I move forward to the face direction???
}
此功能使角色向前移動,但涉及玩家方向。
我想向前移動到面部方向,我該怎么做??
更新文章
public void moveForward(){
Debug.Log("move forward");
speed = 40;
Debug.Log("head.transform.forward.x:" head.transform.forward.x);//1
Debug.Log("head.transform.forward.y:" head.transform.forward.y);//0
Debug.Log("head.transform.forward.z:" head.transform.forward.z);// -1.192093E-07
Debug.Log("this.transform.forward.x:" this.transform.forward.x);0
Debug.Log("this.transform.forward.y:" this.transform.forward.y);0
Debug.Log("this.transform.forward.z:" this.transform.forward.z);1
//somehow this two do the same move,,
this.transform.position = head.transform.forward * vz / 50f * Time.deltaTime;
//this.transform.position = this.transform.forward * vz / 50f * Time.deltaTime;
}
uj5u.com熱心網友回復:
向頭部朝向的方向移動,只需執行
transform.position = head.transform.forward * speed / 50f * Time.deltaTime;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/369713.html
上一篇:如何在unity中跳過元素
