- Home /
onCollisionEnter function
So i have this function on an object :
function OnCollisionEnter(){
Debug.Log(gameObject.name+" collision entered");
rigidbody.isKinematic = false;
}
The function is suppose to make an object fall once my fps character lands on the object.
I actually had the same function working, but they i had to do something, and im not able to get it working again. Im sure its something simple but i feel like i tried everything now to get it back.
Can anyone please help me with this?
Answer by duck · Sep 09, 2010 at 11:27 AM
gameObject.name refers to the name of the gameobject on which this script is placed, not the object that collided with it.
To get that information you need to change your "function" line so that it provides a named parameter, which gets filled with information about the collision whenever a collision occurs, like this:
function OnCollisionEnter( col : Collision ) {
Then, you can read information about the collision by examining the properties of the "col" variable:
Debug.Log(col.gameObject.name + " collided with me!");
For a list of the other properties of the collision that are available to you, see the Collision manual page.
thanks, got no issues with that script, but nothing really happen. No collision or any trace of that anything happen in the console. Is there something other than scripting i have to do to my fps character or the object where i placed the script?
Your answer
Follow this Question
Related Questions
Physics Collision Only Seems to Affect Moving Objects 1 Answer
How to get Animator.GetBool to work as a parameter in OnCollisionEnter in Unity (c#)? 0 Answers
OnCollisionEnter Not working with rigidbody 1 Answer
onCollisionEnter function called from another object. 1 Answer
collision between two objects without using OnCollision,etc. 1 Answer