Cant find an answer for this, may be nooby, question. Well problem is that my enemy object has sphere collider as trigger. An I expect that when this enemy object moves and it’s collider touch another game object(it has collider as well and not moving), OnTriggerEnter() should return touched gameobject. But it return this game object only wheh game object moves.
so how this case can be resolved or is there work around how to detect triggered objects which doesn’t move.
I downloaded your package, put it into the project and the first thing I noticed is that the First Person Controller (“FPC”) had a link to a script that had broken (an error that doesn’t stop the game from running).
Once I had re-attached the NewBehaviourScript to it and ran the game, it started sending out the print statement, correctly identifying that it was being triggered by the FPC and, when I moved the player INTO the cube, that it was also colliding with the cube, exactly as it should.
After correcting the link issue and moving the player into the cube:
Please check your console (“Window” => “Console”, from the menus), if you have this script linking error, that would be why it doesn’t work.
Two more things:
I would avoid making the player a trigger and, instead, make the objects that the player walks into be the triggers.
Regardless of what the trigger is, you may want to use tags to differentiate between collisions at some point (especially if you want the FPC to be a trigger).
function OnTriggerStay (other : Collider)
{
if(other.gameObject.tag == "cube")
{ Debug.Log("I am hitting the cube"); }
if(other.gameObject.tag == "door switch")
{ Debug.Log("If this were a door in Star Trek, it would open automatically for me."); }
}
As far as I’ve tried, it’s worked for me. I’m sorry to be long winded, but maybe this will help.
So, if memory serves:
OnTriggerEnter() is used as part of an object to recognise another object that has moved into the first’s collider at the moment that it does - and only then.
OnTriggerExit() is the opposite, where the collision is only picked up when an object leaves the collider.
OnTriggerStay(), however, is used to have the first object detect any object that is within the bounds of the first’s collider, at every frame that this remains true.
So, could you replace your code, which seems to be:
Give both - the object that triggers the event and the object that has the trigger - a rigidbody. (Maybe it is something smaller: if it is a 2D game check if they have the same z-axis - otherwise it looks as if they would collide but actually they don’t). Hope this helps.