Ball Colide With Character Controller

Hey, Im new to unity but find it very interesting ^^

Ive bin struggeling with a problem for several hours now, and I can cleary see that i need some help with it.

I have a turret firing balls into my world, and when the balls hit my character(First Person Character Controller) i want the game to stop (gameover)

But i dont know how to do this.

Can anyone link me a tutorial or a script that could do this, thank you very much in advance :wink:

I could imagine something like putting a tag on the character controller.
And then tell the ball script that when i hit something with that tag the game would pause and display gameover.

look at the lerpz tutorial, it shows a health and damage system

I cant seem to find anything in there that reflects what i wanna do :open_mouth:

well if you have the ball as if it inflict 100% of the health at once then it should get the game over effect you want

I know how to script it inflicting damage, but i dont know how I get the script to know that the ball has hit the player :S

What do i use for that?

how about something like

if ball.location == player.location
{
gameover
}

That would be a more easyer task i think? :wink:

Use the scripting reference. Search for collision.

Use OnCollisionEnter and/or OnControllerColliderHit, depending on how your objects are set up.

But this only works when its two rigid-bodyes… and when I add a rigid body to my first person character controller it starts jumping around all crazy :open_mouth:

The ‘character controller’ component is a rigidbody already.

Only moving objects need rigidbodies for collision detection.

okay i see, I got it working. but i got several balls… it shoots out 300 balls i have to avoid ^^ so when they touch with each other, the game ends to? how do i tell it that it must do it only when it hits the character controller and not all the other balls jumping around? :wink:

The OnCollisionEnter callback can be passed a collisionInfo struct that will contain the gameObject that collided with it. If you were using an OnCollisionEnter callback on each ball, you could check the gameObject field of the collisionInfo and see if its tag matched a tag you gave to your player.

Okay this seems to work

function OnCollisionEnter (other : Collision)
{
if (other.gameObject.name == “FirstPersonController”) {
print(“Game Over”);
}
}