我有這個杯子裏面含有球。全部2D 我正在使用Rigidbody2d和Collider2d。通過拖動(移動)移動對象會使球從杯子落下
當統一運行並移動杯子(用箭頭鍵)時,球會留在杯子內。我還添加了Android觸控移動杯子的拖動動作。
問題是,當移動杯子過快(通過拖動)時,球從杯子對撞機上掉落(使用Polygon colider 2d)。
代碼運動是:
public float speed = 0.1F;
void Update() {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
我試圖用速度參數玩,但它不會真正的幫助。如果杯子運動太慢,對我來說不是很有用。 我相信這是相關的球或杯的速度/力,使杯子對撞機錯過...
任何幫助,將不勝感激!
嗨,謝謝你的答覆。所以我應該使用AddForce或Velocity?你也可以使用 – Dror
,各有其優點。我喜歡速度,因爲我習慣這樣想。但AddForce同樣好,可能更簡單。 – user3183542
gameObject.rigidbody2D.AddForce(direction); – user3183542