- Home /
Get angle from impact
I have a rigidbody called Ball that collides with small bricks. I'm trying to instantiate an object, Powerup, that has the direction in which the ball collided. The thing is, the Ball doesn't rotate because I locked it like that. Is there anyway to determine from which angle the Ball collided so I can move the Powerup the same direction?
Answer by ThePunisher · Dec 21, 2012 at 06:36 PM
EDIT: You can get the contact points from the collision. All you will need is the contact.normal multiplied by whatever speed you want your powerup to move at.
Here is some example code:
public class CollisionChecker : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
Debug.Log("collision occurred");
foreach (ContactPoint contact in collision.contacts)
{
Debug.DrawRay(contact.point, contact.normal, Color.red, 2.0f);
}
}
}
Answer by SgtBurned · Dec 21, 2012 at 06:28 PM
My idea would be to get a HitNormal and do some math like. Lets say it hits it at 45 Degrees, You would apply force Minus the hit angle in degrees ( Past the Hit Point )
Sorry I couldn't get some code done, Little busy with work ;)