0
我正在嘗試創建一個簡單的平臺。我在觸發器周圍設置瞭如果玩家碰撞的地方,玩家可以啓用ConstantForce,玩家可以按照選定的方向(取決於觸發器)進行推動。這在將玩家向左和向右推動的情況下工作得相當好,但是我遇到問題的時候是玩家在Y軸上被推上去的時候。玩家徘徊一段時間,但每次他下降,他開始越來越低 - 最終退出觸發器。除非他退出觸發器,否則我希望他在空中保持一定的高度。增加ConstantForce只會讓他飛得更高,減少他的質量也有類似的效果。使用ConstantForce模擬風
private ConstantForce getConstantForce;
public GameObject findingThePlayer;
public Vector3 forceDirection = new Vector3();
void Start()
{
//Getting the ConstantForce component from player
findingThePlayer = GameObject.Find("pig_test");
getConstantForce = findingThePlayer.GetComponent<ConstantForce>();
}
void OnTriggerStay()
{
//turning on the players ConstantForce
getConstantForce.enabled = true;
//we set the vector value in editor, depending which way we want the wind to blow
getConstantForce.constantForce.force = forceDirection;
}
void OnTriggerExit()
{
//When player exits trigger, ConstantForce is disabled
getConstantForce.enabled = false;
}
}