建造一堵提高速度统一的墙

Make a wall that boost speed unity

所以...我知道这一定是一件非常简单的事情,但我坚持了好几天,基本上我需要的是,当球撞到墙上(对撞机)时,它开始朝一个方向加速,如下图,但我需要用物理来做,我不能只插值位置。

你首先需要一个平行于地面的矢量!

您可以使用 Collider.ClosestPoint 来找到墙壁对撞机上离球位置最近的点。

由此您可以知道 ground/wall 的平面法线,因此您可以使用 Vector3.ProjectOnPlane 将通常的移动方向转换为平行于地面的方向。

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; 
}

注意:在智能手机上打字,但我希望思路清晰,这提供了一个良好的起点