Entering inside of colliders

Hey guys, When my player runs into a barrier, I want them to completely stop. No movement command should work except for clicking directly sideways from where they’re stuck or backwards the same way they came from. (So the only way to get unstuck is to click in a 180 degree radius that goes from the left to the right hand side when you are facing the barricade)

I’m encountering a few problems: Screen capture - bfe2aa4ded004ab499ef400ef0a06fed - Gyazo
I keep partially intersecting the blockade. I want it to completely stop… Like this - but clicking won’t do anything because if I stop the agent in OnCollisionEnter, clicks won’t register because OnCollisionExit is never called.

***This doesn’t work (it’s closer to how I want it but it still has the “jumping” problem when you click on the far side of the barricade more than once. I think this is because we’re touching the collider already)- I tried it - here’s what happens: Screen capture - 81f2731ec1ba6d60d81eea2400c1883a - Gyazo
In my barricade class in OnCollisionEnter:
playerRef.GetComponent().enabled = false;
In my clickToMove script:
click some location
playerRef.GetComponent().enabled = true;
NavMeshAgent.SetDestination(The place I clicked);


My click to move script is just that - I click a location and it eventually calls:
NavMeshAgent.SetDestination(some place I clicked)

Here’s the my OnCollisionEnter and Exit for the barricade class that I have:
Code (CSharp):

Firstly, what is the input you are using? Mouse or keyboard. If keyboard, what keys?

Next, how this should work is:

  1. Move the player
  2. On collision enter → set a boolean in the player’s script to true.
  3. Once the boolean is on, in the Update loop of the same player script, check for the input command. Whatever is tthe input check if its directly backward or if its sideways.
  4. if its in front, do nothing
  5. else move.

The playerRef.transform.position will only change if the input is in the direction you want …

Hope this works.

Hey - I’m using click to move (mouse). Thanks for the reply. How might I check if mouse input is directly backwards or sideways?

When you use mouse click, you will be using the drag event.

The following might help:

  1. Take the start position of the mouse click on the screen (x,y coords) and convert into world space coords 93d)
  2. On drag or mouse move take the current position (x,y coords) and convert into world space coords 93d)
  3. find the direction between startPoint and currentPoint
  4. with this vector you will do a raycast and check if the collider is in front of it or not

if the ray doesnt collide with the collder then you move the object.

hope this helps.