Hello!
Here’s the problem.
Let’s say there is a ball moving with constant speed 50, so rigidbody.velocity.magnitude is 50 too. At some frame it is bouncing off the surface. I want to check out it’s speed on collision, and set speed to 50 if it is lower than 50.
However, because the ball is being reflected back, distance between points of previous and current frame is definitely less than 50.
Just imagine:
- point A - ball position in prev. frame,
- point B - ball position on collision,
- point C - ball position in current frame (bounced back).
Is it any way to get not the distance magnitude between A→C, but the whole A→B→C route?
private Rigidbody rb;
private void OnCollisionEnter(Collision other)
{
if (other.collider.name == "Pad")
{
ContactPoint cPoint = other.contacts[0];
rb.velocity = Vector3.Reflect(rb.velocity, cPoint.normal);
if (rb.velocity.magnitude < 50)
{
rb.velocity = rb.velocity.normalized * 50;
}
}
}