- Home /
bouncing circle off another circle
Hello,
I am trying to shoot a cricle onto another circle. The first circle has to bounce off the second one, while the second one is standing still. Can someone give me a hint how I can achieve this? In fact it has to be cost efficient due to mobile game programming.
Thank you so far :)
Can't you just use the rigidbody component? Calculations will probably be way much more optimize than anything you will come up with.
This should make you feel like using the rigidbody component, http://en.wikipedia.org/wiki/Elastic_collision
Hi, I meant circles, but ended up using sphereColliders.
This is what i have so far. I am calculating the angles between the static sphere and the shooting sphere on collision to get the normal angle between them, calculating the angle between shooting direction angle and normal angle, multiplicating it by two to get the right exit angle and then trying to change the direction. And it changes, but wrong:
function OnCollisionEnter(collision : Collision) {
var dynCircle = this.transform.position;
var statCircle = collision.transform.position;
var collisionNormal = dynCircle - statCircle;
var oppositeDir = -dynCircle;
var normalAngle = Vector3.Angle(Vector3.back, collisionNormal);
var shootingAngle = Vector3.Angle(Vector3.back, oppositeDir);
var angle = (normalAngle - shootingAngle) *2;
this.transform.rotation = Quaternion.AngleAxis(angle, Vector3.up);
}
I make the same question as fafase. Why not use a rigidbody? It does that out of the box.
Answer by Spinnernicholas · Nov 27, 2013 at 09:47 PM
Thanks to the new built-in 2D tools they have Rigidbody2D now.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122923im_/https://answers.unity.com/themes/thub/images/avi.jpg)