建造一堵提高速度統一的牆 (Make a wall that boost speed unity)


問題描述

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

所以...我知道這一定是一種非常直接的事情,但我堅持了好幾天,基本上我需要的是,當一個球撞到牆壁(對撞機)時,它開始加速朝著一個方向,如下圖所示,但我需要使用物理學來完成,我不能只插入位置。

Exemplification


參考解法

方法 1:

You would first need a vector parallel to the ground!

You can use Collider.ClosestPoint in order to find the closest point on the walls collider to the ball Position.

From this you then know a plane normal for your ground/wall so you can then use Vector3.ProjectOnPlane in order to convert the usual move direction into one parallel to the ground.

private void FixedUpdate () 
{
    var ballRb = ball.GetComponent<Rigidbody>();
    var wallCollider = Wall.GetComponent<Collider>();
    var hitPoint = wallCollider.ClosestPoint(ballRb.position);

    // normal of ground (= vector from hitPoint to ball)
    var groundNormal = (ballRb.position ‑ hitPoint).normalized;

    // project the given velocity onto the ground
    var newVelocity = Vector3.ProjectOnPlane(ballRb.velocity, groundNormal);

    // optionally increase the speed of needed e.g.
    //var newDirection = newVelocity.normalized;
    //var newMagnitude = newVelocity.magnitude * 1.1f; // or any multiplication or addition factor
    //newVelocity = newDirection * newMagnitude;

    // and finally reassign the new velocity
    ballRb.velocity = newVelocity; 
}

Note: Typed on smartphone but I hope the idea gets clear and this provides a good start point

(by Renan KlehmderHugo)

參考文件

  1. Make a wall that boost speed unity (CC BY‑SA 2.5/3.0/4.0)

#game-physics #unity3d






相關問題

Android AndEngine:簡單的精靈碰撞 (Android AndEngine: Simple sprite collision)

Box2D - 收集硬幣 (Box2D - collect a coin)

LibGDX - 只有可拖動的運動 (LibGDX - only draggable movement)

Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

2D 平台遊戲:為什麼讓物理依賴於幀率? (2D platformers: why make the physics dependent on the framerate?)

基於脈衝的物理 - 在輕物體上堆疊重物體 (Impulse based physics - Stacking heavy object on light object)

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

向前和橫向球員運動 (Forward and Sideways Player movement)

如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)







留言討論