Velocity relative to Local Axis


Can I add velocity to an object relative to it’s local axis?

This is the snippet of code:

rigidbody.velocity.z = MovSpeed;

But it’s relative to the world, I want it to be relative to the local object.

Here is the full script.

private var lookRotationPoint = Vector3;

public var MovSpeed : float = 10.00;

	function Update()
        var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        var hit : RaycastHit;
        if (Physics.Raycast(ray, hit))
            if (hit.collider.gameObject.tag == "Plane")
                var lookRotationPoint = hit.point - transform.position;
                transform.rotation = Quaternion.LookRotation(lookRotationPoint.normalized);
                transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0);
					"Code goes here"
			rigidbody.velocity = Vector3(0,0,0);

Convert the current velocity to local space, modify the z component and convert it back to world space:

  var locVel = transform.InverseTransformDirection(rigidbody.velocity);
  locVel.z = MovSpeed;
  rigidbody.velocity = transform.TransformDirection(locVel);

But if you just want to add/subtract a velocity in the forward direction, use transform.forward:

  rigidbody.velocity += transform.forward * MovSpeed;