Physics ignored when using NavMeshAgent enabled
I have a platform bug and workaround using NavMeshAgent.
The player walks onto an invisible platform. the platform is a basic 3D cylinder.
the platform collision triggers the platform to be visible
The next Update starts the platform animation to lift the player.
The issue is that the platform ignores the player pill and children. Players Components used are :
CapsuleCollider, isTrigger false (the Lift game object has the collision trigger)
RigidBody, UseGravity true
NavMeshAgent
I spent the better part of a day moving these components order around, adding/removing, rebuilding NavMesh. Every time, the platform goes up it ignores the Player - until I removed the NavMeshAgent and started the player on the platform. Now I consistently have it working because I disable NavMeshAgent when the collision starts (see function below).
That workaround right there is messed up, but it allowed me to continue past the basic setup of ,"lift player pill on platform".
Anyone have any pro tips on setting up my scene better so this conflict doesn't happen?
public class DetectLift : MonoBehaviour {
public GameObject PlayerObject;
private Component[] LiftEffect;
public Animator LiftUp;
private bool PlayerReady;
// Use this for initialization
void Start () {
PlayerReady = false;
}
//Player must find the hidden platform
//when they find the platform hide the hints and enable the visuals to reveal the lift
void OnTriggerEnter (Collider other)
{
LiftEffect = GetComponentsInChildren(typeof (MeshRenderer));
if (LiftEffect != null)
{
foreach (MeshRenderer Toggle in LiftEffect)
Toggle.enabled = !Toggle.enabled;
}
//parent the Player to the platform to make the animation smoother
PlayerObject.transform.parent = this.gameObject.transform;
PlayerReady = true; //checked on Update to end the level
//WORKAROUND: there is an issue with the platform not picking up the player unless the NavMeshAgent on the player is disabled
//since the player is now a child we can rehash the previous component check to disable it
LiftEffect = GetComponentsInChildren(typeof (NavMeshAgent));
if (LiftEffect != null)
{
foreach (NavMeshAgent Toggle in LiftEffect)
Toggle.enabled = false;
}
}
Your answer

Follow this Question
Related Questions
How to make SphereCastAll retrieve all hits with a concave mesh ? 0 Answers
Changing shape of player jump path 0 Answers
Spawned objects sink through ground, when over 3 clones 0 Answers
Collision Detection issue 1 Answer
How to determine on collision if an object is rotated in a certain way 1 Answer