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\$

2 Answers 2

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .