I have an issue (see the video link) with my Android-based game:
Sometimes the player glitches through the floor when clicking on different spots (most of the time when clicking on the lower floor).
I checked everything navigation static/not navigation static, and of course I used the layers walkable/not walkable. The floor is walkable. All the other stuff is not.
This is the important part of the PlayerMovement Script:
// This function is called by the EventTrigger on the scene's ground when it is clicked on.
public void OnGroundClick(BaseEventData data)
{
Debug.Log("Click");
// If the handle input flag is set to false then do nothing.
if (!handleInput)
return;
// The player is no longer headed for an interactable so set it to null.
currentInteractable = null;
// This function needs information about a click so cast the BaseEventData to a PointerEventData.
PointerEventData pData = (PointerEventData)data;
// Try and find a point on the nav mesh nearest to the world position of the click and set the destination to that.
NavMeshHit hit;
if (NavMesh.SamplePosition (pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
destinationPosition = hit.position;
else
// In the event that the nearest position cannot be found, set the position as the world position of the click.
destinationPosition = pData.pointerCurrentRaycast.worldPosition;
// Set the destination of the nav mesh agent to the found destination position and start the nav mesh agent going.
agent.SetDestination(destinationPosition);
Debug.Log(hit.position);
Debug.Log(destinationPosition);
agent.Resume ();
}
This shouldn’t happen ofcourse. Do you have other scripts warping or detaching the navmesh agent from the transform ?
Selecting the GO with the agent transform - might give some hints – looking at the navmesh agent debug gfx.
I have this issue and I can’t for the life of me find a solution, I know this is an old topic, but I haven’t found any other example of exactly what’s happening to me, did OP or someone else maybe find a fix for this, or a way to point to the issue?