Hey guys i have two things to ask,
- I have 2 colliders, when on falls onto the other one the script works, but if i walk up to it after it has fallen and it is standing idle then the script does not work.
I need some help -_-
- Whats the coding ( java ) for OnTrigger() events?
to use triggers you should mark your colliders as triggers. check the "is trigger" box in collider's inspector. then there are three events that you can use. OnTriggerEnter will be called when a collision starts and OnTriggerExit will be called when the collision ends and two objects don't overlap. OnTriggerStay will be called once in each frame between OnTriggerEnter and OnTriggerExit. stay means two colliders are in a collision. after your object fall in to the other one, it should go back and exit from other's collider region and then come back in to call OnTriggerEnter again.
function OnTriggerEnter (other:Collider)
the function takes one argument that tells you who is colliding with you.
if(collision.gameObject.tag == "Player")
This code is attached to a cube that has a collider,
When i use the standard First Person Controller to touch the box ( walk over to it ), Nothing happens
I know this code works only if its a moving object
And yes my First Person Controller has the tag " Player "
Thanks for help so far, and i'am sorry for posting two questions in one.
OnControllerColliderHit() is only called on the GameObject containing the CharacterController Component, not on the colliding rigidbody, so you'd have to do it the other way round, detecting if your character hit something and then determining if it was a cube/crate whatsoever.
Oh and the parameter for OnControllerColliderHit is of type ControllerColliderHit. ;)
It's a bit hard to tell you what you're doing wrong if you don't say what you are actually doing... (code).
What you should look at is if all your objects have some sort of Collider attached to it, and that at least one of them is a dynamic (not kinematic) rigidbody. Otherwise Collisions won't work. I suspect that you are using a CharacterController to move your character, so OnCollisionEnter() won't be called. Try using the OnControllerColliderHit() for Collisions involving your character.
Triggers are different from Collisions. To receive trigger events you have to mark your Collider as Trigger. Then use the OnTriggerEnter/Stay/Exit methods of the Collider.
"how do i assign a key for the trigger"
You'll need to manually check whether the key is pressed or not in your OnTriggerEnter code using Input.GetKey() or a similar function.