1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.