I want the player to stay confined within the walls of the level.
I want the enemy to do something when it touches the wall.
I only have one wall. If I use the trigger function on the wall collider. The player will pass through it.
If I leave the trigger off. The trigger will not occur when the enemy touches the wall.
I was thinking I could have two walls. One with a trigger one without. But that seems excessive.
Is there a smarter way to do this?
Make them colliders not triggers. This will keep everything in. In the enemy script use OnCollisionEnter. This will be called when he collides with something. You could check the tag in there to make sure its a wall as well.
function OnCollisionEnter (collison : Collision) {
if(collision.gameObject.tag == "wall")
{
currentState = enemyState.look;
}
}
Doesn’t seem to work…
are you sure the walls tag is actually set to wall?
Also one of the two object colliding need a rigidbody for it to register.
yep. walls all have the right tag. The trigger enter I had before worked fine. but my player kept going through everything.
so the player and the walls colliders onTriggers are both set to false? and one of them has a rigidbody?
yes. The enemy has a rigidbody.
and the triggers aren’t on.
well you have something wrong. take out the tag check and put a debug.log in there and see if collisions are registered
the collisions aren’t registering on two cubes both with rigid bodies.
I can’t even get it to work bare bones.
is the script actually on one of them. and are they both colliders and not triggers
They are both colliders. but trigger is not checked.
is the script on one of the cubes
okay. I got it to work. when the cube falls and touches the floor…
So once the collision is detected. can it be detected again? Say it’s constantly colliding with the floor?
if you use OnCollisionEnter it will only be called the first time it collides with something. OnCollisionStay will continuously be called if its colliding with the object. And OnCollisionExit will be called after the objects stop colliding
How would this work in relationship to a character controller?
hey! thats what I needed all along. thanks!
no problem lol. learn to search the documentation it will help you learn and you will find what you need faster for the most part.
1 Like