Hi,
I am trying to make a pang clone game : bouncing balls you hit them with harpoon like weapon they split into half.
-The walls are bouncy with 0 friction, the balls are rigidbodies.
My issues are:
1-collision between the balls I want them to ignore each others.
—they don’t the first time then after the first collision they start ignoring
2-some times the ball get stuck on the y or x axis bouncing
-how can I add some multiplier to avoid this issue.
Here is the code:
var impact : AudioClip;
var minSpeed:float=5;
var maxSpeed:float=10;
var curSpeed:float=0;
var colSpeedMulti:float=1.1;
var myball:GameObject;
function Start () {
rigidbody.AddRelativeForce(0,-minSpeed,0);
}
function FixedUpdate () {
curSpeed=Vector3.Magnitude(rigidbody.velocity);
if(curSpeed > maxSpeed)
{
rigidbody.velocity /= curSpeed / maxSpeed;
}
if(curSpeed < minSpeed && curSpeed > 0)
{
rigidbody.velocity /= curSpeed / minSpeed;
}
}
///the collision function:
//1-balls need to ignore each others,anything else bounce
function OnCollisionEnter(col:Collision){
audio.PlayOneShot(impact);
if(col.collider.gameObject.CompareTag("ball")){
Physics.IgnoreCollision(col.collider,collider);
}
else{
/// we need some multiplier to avoid getting stuck
rigidbody.velocity += rigidbody.velocity * colSpeedMulti;
//score.Score++;
//lives.currentlives--;
}
}
// hitting the balls with arrow
// if they are not small enough split them otherwise destroy the ball
function OnTriggerEnter (other : Collider) {
if(other.gameObject.CompareTag("arrow"))
{
if(transform.localScale.y!=0.5){
Destroy(other.gameObject);
Destroy(gameObject);
var ball=Instantiate(myball,transform.Find("span1").transform.position,Quaternion.identity);
ball.transform.localScale /=2;
var ball2=Instantiate(myball,transform.Find("span2").transform.position,Quaternion.identity);
ball2.transform.localScale /=2;
paddle.weaponactive=false;
}
else if(transform.localScale.y==0.5){
Destroy(other.gameObject);
Destroy(gameObject);
paddle.weaponactive=false;
}
}
}