Sunday, 8 March 2015

Can't get onTriggerEnter to work in "Roll-a-ball" tutorial?

Was following the "Roll-a-ball" tutorial but can never get the "OnTriggerEnter" to work in the "05. Create pick-up objects" module.

The settings for player object is as below:

The settings for the Prefab object "Pickup" is as below:

When the "Is Trigger" for Box collider in "Pickup" prefab is ticked, the sphere/Player object just went through the "Pickup" object as if it does't exist, and "onTriggerEnter" in the "PlayerController" script (attached to the Player object) does not get called. When it's not ticked, the sphere/Player object will bump into the Pickup object and stopped.

Found this similar question in answer.unity3d.com, however it's due to typo in the "Tag" name. To avoid confusion, I later purposely renamed my tag to "PickMeUp", plus added a few Debug.log in onTriggerEnter in the "PlayerController" script as shown below. So that even if the tag name doesn't match, there should be at least a line "enter onTriggerEnter" been logged on the console when it was called, but strangely nothing gets logged...

I am on Unity 4.5.2. Both the player and Pickup objects have collider and rigidbody component added. What else could be wrong? I am totally confused....

[Update]
Asked question in answers.unity3d.com

[Update]
Question got rejected, because it should be "OnTriggerEnter", not "onTriggerEnter" - needs upper case "O", silly me. Certainly a big lesson learned.

No comments:

Post a Comment