所以設法在反彈中編碼,但無法弄清楚如何使反彈更小并最終使其停止。有什么建議嗎?
public Vector3 velOriginal;
public float E;
private Vector3 vel;
private Vector3 pos;
private Vector3 gravity = new Vector3(0.0f, -9.81f, 0.0f);
//public bool changeGravity = true;
// Start is called before the first frame update
void Start()
{
pos = this.transform.position;
vel = velOriginal;
}
// Update is called once per frame
void Update()
{
pos = pos vel * Time.deltaTime;
vel = vel gravity * Time.deltaTime;
this.transform.position = pos;
if (this.transform.position.y < 0f)
{
pos.y = 0.52f;
this.vel = velOriginal * E;
}
}
uj5u.com熱心網友回復:
為什么沒有物理引擎?如果沒有它,您將需要指定哪些幾何圖形相互碰撞以執行幾何計算,以便檢查它們是否發生碰撞。
如果沒有物理引擎,我認為您的意思是不使用剛體并專門針對運動避免物理。在那種情況下,積分速度以獲得 pos 和積分加速度以獲得速度在更新中很好,那么我將反轉 Y 軸速度方向OncollisionEnter()。
所以,
void Update()
{
pos = vel * Time.deltaTime;
vel = gravity * Time.deltaTime;
}
和:
OnCollisionEnter(Collision collision) {
if (isCollidingSurface) { //check somehow if is the collision of interest
vel.y = -Mathf.Abs(vel.y)
}
}
為此,我認為您需要一個游戲物件中的OnCollisionEnter和一個剛體OnCollisionEnter,這意味著使用物理系統。然而,這并不意味著 gamoObject 會隨著剛體物理、力等移動,這是我認為你試圖避免的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405084.html
標籤:
