- Home /
pang clone game issues
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;
}
}
}
Answer by Eric5h5 · Aug 14, 2011 at 09:48 PM
Use collision layers for the balls so they ignore each other.
i am adding them at runtime and that will make it even harder
Adding them at runtime does not make it harder. Just set the layer in the prefab.
the problem at a point in the game i will have 16 balls running does that mean i need 16 different layers --Thanks
No, it just means you need to make the "balls" layer not collide with itself.
Your answer
Follow this Question
Related Questions
how the ball bounces of equal in angles? 1 Answer
Bouncing Ball and Walls 1 Answer
Sphere Goes Crazy 3 Answers
How to make an infinite mass solid body 1 Answer
Reducing bounce on simple boxes 0 Answers