Hi everyone! I’m having some problems with physics on my project. When a ball collides with a collider or other ball in a considerable speed, both balls get the inverse direction (thats right). But, if one ball is too slow, the faster one, hits and takes the inverse direction, but the one which was slow, continues slowing down due to friccion on ground. I want to at every collision the balls get some speed boost in the inverse direction. I think you understand… (my english is sooooooooo bad
) Here’s the code:
using UnityEngine;
using System.Collections;
public class ballControl : MonoBehaviour {
Rigidbody myRigidbody;
Vector3 oldVel;
void Start () {
myRigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate() {
oldVel = myRigidbody.velocity;
}
void OnCollisionEnter (Collision c) {
ContactPoint cp = c.contacts[0];
// calculate with addition of normal vector
myRigidbody.velocity = oldVel + cp.normal*1.0f*oldVel.magnitude;
// calculate with Vector3.Reflect
myRigidbody.velocity = Vector3.Reflect(oldVel,cp.normal);
// bumper effect to speed up ball
myRigidbody.velocity += cp.normal*1.0f;
}
}