- Home /
Player colliding with Ball problem.
So I made a sphere and I am trying to check if I am colliding with this sphere. I am using this code
function BallControllerColliderHit(hit : ControllerColliderHit)
{ if(hit.gameObject.name == "dodgeball") { hit.gameObject.animation.Play("ball_spin"); }
}
Pretty much does not work. The animation works because I have it play automatically and it spins my ball, so thats not the problem. I have attached this script to my player which was a "First Person Controller" but it is not working. I have also used print("Collided with Ball"); in place of the animation and that did not work either but I can not think of anything wrong with the conditions.. And the sphere is tagged "dodgeball" correctly.
Answer by Lo0NuhtiK · Dec 29, 2011 at 10:09 AM
You need to use OnControllerColliderHit , rather than BallControllerColliderHit --- you also say you "tagged" the sphere as dodgeball, but in your code you check to see if it's "named" dodgeball, you need to check the "tag" if that's what you're meaning to check, not the name.
Thanks! So I pretty much did not have that function defined in my FPS controller script. Not only is it playing the animation, but it is rolling as well. Two birds with one stone. I would give a thumbs up but it wont let me.
So for anyone that has a similar problem like this in the future.. Use the link he posted and paste that into your first person controller script. I assumed it was already defined, but it wasnt. Unity cant call it if it doesnt know what it is.