- Home /
(ControllerColliderHit) won´t detect collition
Hey! Let me introduce myself first :D My name is Paul, I´m new here... I just started using Unity and I love it!! I´m starting with this practice project where all I want is my "Contruction Worker" to hit a ball when he touches it. I have a scene with the contruction guy and the sphere over a terrain. To reach my objective I wrote this js code and added it to the contruction guy:
var speed : float = 5;
function onControllerColliderHit (hit:ControllerColliderHit){
if(hit.gameObject.tag == "ball"){
Debug.Log("We hit the ball");
hit.rigidbody.AddForce(transform.forward * speed);
}
}
Problem is... ball doesn´t move... and debug doesn´t even send a message. I don´t understand why this is happening giving that both char and ball are detecting the terrain, even the ball bounces (I make it start a bit high so I make sure gravity is ok)
would you please help me solve this? Thankyou :D
Not sure if this will work, so ill add it as a comment: Firstly, your OnControllerColliderHit() should start with a capital O, also try indenting your Debug() and addforce() statements.
heeellll it worked!!! The capital O did the thing. Thankyou so much!!you were very helpful.
If you want, write in the answere box and I will choose it as the correct one and you can get some karma for your unvaluable help. It would also help others who might find the same problem, to solve it faster if they see that the right answere is allready given before they come in. It´s a trible Win Combo ;)
Answer by jerobinson · May 30, 2013 at 05:53 AM
function onControllerColliderHit (hit:ControllerColliderHit){
should be changed to:
function OnControllerColliderHit (hit:ControllerColliderHit){
With capitol O :)
Your answer
Follow this Question
Related Questions
How can I use OnControllerColliderHit to hit ONCE? 2 Answers
How to cast/convert a ControllerColliderHit into a Prefab 2 Answers
android version of game shows error 1 Answer
How to make Step Offset 0 when Character Controller makes contact with certain tag? 0 Answers
How to get a specific contact point from a CharacterController collider hit? 1 Answer