Can I get the speed of a rigidbody object? Or Set the speed of it?
yes, the rigidbody has a property called velocity which you can get if you use GetComponent on a varible with type rigidbody and then call for the property.
As such:
private Rigidbody someRigidBody;
private float someRigidBodySpeed;
void Awake()
{
//Checks if the component actually exists at all
if (GetComponent<Rigidbody>() != null)
{
//Set the object you just proved existed
someRigidBody = GetComponent<Rigidbody>();
}
else
{
//If it does not exist report the problem ( normally a null would cause a
//crash/null reference exception during compilation ) depending on what's
//happening. Both should be avoided
Debug.LogError("Rigidbody missing in , can put name of class here, in awake method");
}
}
void Update
{
//Extracts the speed from the rigibody
someRigidBodySpeed = someRigidbody.velocity;
}
For more information , or if I made some syntax error please look here Setting the speed you will need to do with physics , like AddForce, you are physically manipulating objects that way OR you can overwrite the velocity property since it has write permissions (as the first link shows)