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):
- public void OnCollisionEnter(Collision collision)
- {
- Debug.Log(“Enter”);
- playerRef.GetComponent().SetDestination(transform.position);
- //playerRef.GetComponent().enabled = false;
- //Debug.Log(“OnCollEnter”);
- ////entered = true;
- //Debug.Log("Enter : " + collision.collider);
- //if(collision.collider != playerRef.GetComponent())
- //{
- // return;
- //}
- //playerRef.GetComponent().isStopped = true;
- //Vector3 dest = playerRef.GetComponent().destination;
- //Vector3 current = playerRef.GetComponent().transform.position;
- //Vector3 direction = (dest - current).normalized;
- //direction.x = direction.x * .03f;
- //direction.y = 0;
- //direction.z = direction.z * .03f;
- //Debug.Log("Direction: " + direction);
- //playerRef.transform.position = playerRef.transform.position - direction;
- //playerRef.GetComponent().SetDestination(playerRef.GetComponent().transform.position - direction);
- //StopPlayer(collision);
- }
-
- public void OnCollisionExit(Collision collision)
- {
- Debug.Log(“Exit”);
- //playerRef.GetComponent().isStopped = false;
- }