I need to know how I can get the velocity from one object and copy it to another object with only the x and z axis.
void CopyVelocity(Rigidbody from, Rigidbody to)
{
Vector3 vFrom = from.velocity;
Vector3 vTo = to.velocity;
// Move the values you want for each exis
vTo.x = vFrom.x;
// vTo.y = vFrom.y; // Leaving y-axis as is
vTo.z = vFrom.z;
to.velocity = vTo;
}
Just get the Rigidbody and then it’s velocity:
//The GameObject with the original velocity
public GameObject FirstOBJ;
//The second GameObject
public GameObject SecondOBJ;
SecondOBJ.GetComponent().AddForce(new Vector3(FirstOBJ.GetComponent().velocity.x, 0f, FirstOBJ.GetComponent().velocity.z));
It should work fine. If not, answer me in this post.
Uri.