Is there a way of changing speed of an object at certain time? I want to change my speed to my initial speed after colliding with any object. I have already added bounce Physics to my colliding objects and player object with Friction set to 0. Please help.
2 Answers
Get the Rigidbody component. Then change the velocity value.
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void ChangeSpeed()
{
rb.velocity = new vector3(x,y,z); //place your value in xyz
}
For further reference: Unity Physics Rigidbody Velocity
You could apply a force opposite to it for decceleration or a force in the movement direction for acceleration.
Example:
for acceleration:
GetComponent<Rigidbody>().AddForce(transform.forward * FORCE_CONSTANT);
or for desceleration:
GetComponent<Rigidbody>().AddForce(-transform.forward * FORCE_CONSTANT);