(Unity)物体の速度をいったん0にする方法

(加速装置のスクリプト)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StopAccel : MonoBehaviour
{
    public Vector3 pos;

    private void OnTriggerEnter(Collider other)
    {
        Rigidbody rb = other.GetComponent<Rigidbody>();

        rb.AddForce(new Vector3(pos.x, pos.y, pos.z), ForceMode.VelocityChange);
    }
}

(実験結果)


(スクリプトの改良)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StopAccel : MonoBehaviour
{
    public Vector3 pos;

    private void OnTriggerEnter(Collider other)
    {
        Rigidbody rb = other.GetComponent<Rigidbody>();

        // 速度をいったん0にする。
        rb.velocity = Vector3.zero;

        rb.AddForce(new Vector3(pos.x, pos.y, pos.z), ForceMode.VelocityChange);
    }
}

(改良後の実験結果)