Problem with Vector3.Reflect();

Ok folks, so here’s a piece of my code that i almost managed to make work:

Vector3 ballStartDirection;

void FixedUpdate() {
	
	if (ballReleased == true)
	{
	
		rigidbody.MovePosition(rigidbody.position + ballStartDirection * Time.deltaTime);	
	}
}

void OnCollisionEnter(Collision collision)
{
	if (ballReleased == true)
	{
		var contactNormal = collision.contacts[0];
		var rot = Quaternion.FromToRotation(Vector3.up, contactNormal.normal);
		var pos = contactNormal.point;
		var rv = collision.relativeVelocity.magnitude;
		
		var direction = gameObject.rigidbody.transform.position - pos;
		ballStartDirection = Vector3.Reflect(pos, direction);
		
	}

}

I did something wrong in this code logic… the ball was supossed to bounce “off” the objects, and not to go inside…

Someone can explain me what i did wrong?

Witha Reflect(), you want the normal to the surface. You are using the point of contact in 3D space. So the vector you are using is going from the origin to the point…not what you want. Your other vector also has problems. Unless your object is a sphere, your use of transform.position will not necessarily match up with the velocity, plus you have the vector going the wrong way. Use rigidbody.velocity instead. You could should be something like:

var normal = contactNormal.normal;
ballStartDirection = Vector3.Reflect(rigidbody.velocity, normal);