Two physics problems.

Hi guys:
I have two problems about physics engine.
First, in my game, there are not only one ball in a single scene, and I want the balls don’t collide with each other. Can I do this in unity? And how?
Then, I use AddForce() to add force to the ball. In most cases, it works fine. But some times, after the inputs, the ball doesn’t move. So I input again and again, then the ball moves, with a extremely fast speed. I think maybe the last AddForce() gathers all the forces before and shoot the ball at this time. Why would this happen? What can I do.

In response to the balls not colliding with each other, you could do it a couple ways. The most intuitive is just to use Physics.IgnoreCollision() for each ball in relation to every other ball (ie-iterate through an array of the balls, for each ball in the array, call Physics.IgnoreCollision() on every other ball). Another way to go would be just to put the balls on the same layer and have them ignore collisions with that layer.

Thanks for reply. It’s really helpful.
But, how to do the second way? I mean make the collider ignore collision with that layer.

@Maker16: you can certainly use layers to prevent raycasts from detecting a collider, but are you sure you can also disable collisions with a layer?

@Jay: can you post the script you are using to move the ball? I’m not quite sure what is going on with the physics there.

Here is the script in a level script, in function update, to get the input. And the ballScripts is a array to cache all the balls’ scripts. The force added to the ball accords to the mouse’s moving velocity. And I use a stack to manage all the balls.

// Capture the mouse.
var mouse : Vector3 = Input.mousePosition;
// Make sure the mouse position is in the screen.
// After transplant to the iPod, we can delete these sentences.
if(mouse.x > Screen.width)
mouse.x = Screen.width;
else if(mouse.x < 0)
mouse.x = 0;

if(mouse.y > Screen.height)
mouse.y = Screen.height;
else if(mouse.y < 0)
mouse.y = 0;

if(Input.GetMouseButtonUp(0) isThrowing){
var timeFactor : float = Time.time - throwingTime;
timeFactor = timeFactor < Time.deltaTime ? Time.deltaTime : timeFactor;
var factor : float = (mouse.y - startMousePosition.y) / timeFactor;
var direction : Vector3 = mouse - startMousePosition; // Throw direction.
direction.z = direction.y;
direction.y = 0;
//print(factor + “”);
direction.Normalize();
if(factor > 0){ // Throw the current ball.
if(ballScripts[index])
ballScripts[index].Throw(direction, factor);
index–;
}
else{
if(ballScripts[index])
ballScripts[index].SetPoint(ballPos[index]);
}
isThrowing = false;
}

if(Input.GetMouseButtonDown(0)){
startMousePosition = mouse;
throwingTime = Time.time;
isThrowing = true;
ballScripts[index].SetPoint(startPoint);
}

And here is the script in ball script. This script is attached to the balls.
function Throw(direction : Vector3, factor : float){
myRigidbody.AddForce(direction * basicForce * factor);
throwing = true;
}