Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CDMcGwire · May 17, 2015 at 08:07 PM · navmeshnavmeshagentglitch

Why do my Navmesh Agents pop through the center axis of the mesh?

I have a simple plane that I've generated a mesh for and two capsules with Navmesh agents attached. They move around just fine, but when moving right along the Z-Axis or X-Axis (Which are lined up with the Global Z and X Axis) the capsules will glitch up and down but still move for the most part. Occasionally they will full glitch out.

I get this error on the camera, but I'm not really surprised by this one.

Screen position out of view frustum (screen pos 917.000000, 802.000000) (Camera rect 0 0 982 552) UnityEngine.Camera:ScreenPointToRay(Vector3) PlayerController:RotatePlayer(Single, Single) (at Assets/Scripts/PlayerController.cs:61) PlayerController:PlayerMovement(Single, Single) (at Assets/Scripts/PlayerController.cs:39) PlayerController:FixedUpdate() (at Assets/Scripts/PlayerController.cs:29)

Here's a video I made to demonstrate what is happening.

The Capsules have Navmesh Agent components and Rigidbodies. Here is the code I use to move the player.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour 
 {
     private int jumpState = 0;
 
     public float speedScale = 1f;
     public float jumpHeight = 1f;
     // public float turnSmoothing = 15f;
     
     private bool isGrounded;
 
     private Rigidbody rb;
 
     // Use this for initialization
     void Start () 
     {
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
         // Horizontal movement
         float x = Input.GetAxis("Horizontal");
         float z = Input.GetAxis("Vertical");
 
         PlayerMovement(x, z);
     }
 
     void PlayerMovement(float h, float v)
     {
         if(h != 0f || v != 0f)
         {
             MovePlayer(h, v);
         }
 
         RotatePlayer(h, v);
 
         if(Input.GetButton("Jump") && (jumpState < 10))
             Jump();
     }
 
     void MovePlayer(float h, float v)
     {
         Vector3 targetPos = new Vector3(h * speedScale, 0f, v * speedScale);
         rb.MovePosition(transform.position + (targetPos * Time.deltaTime));
     }
 
     void RotatePlayer(float h, float v)
     {
         /*
         Vector3 targetDirection = new Vector3(h, 0f, v);
         Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
         Quaternion smoothedRot = Quaternion.Lerp(rb.rotation, targetRotation, (turnSmoothing * Time.deltaTime));
         rb.MoveRotation(smoothedRot);
         */
 
         // Create a ray from the mouse cursor on screen in the direction of the camera.
         Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
         
         // Create a RaycastHit variable to store information about what was hit by the ray.
         RaycastHit floorHit;
         
         // Perform the raycast and if it hits something on the floor layer...
         if(Physics.Raycast (camRay, out floorHit, 300f, 1 << 8))
         {
             transform.LookAt(new Vector3(floorHit.point.x, transform.position.y, floorHit.point.z));
         }
     }
 
     void Jump()
     {
         rb.AddForce(Vector3.up * jumpHeight);
 
         if(!isGrounded)
             jumpState++;
     }
     
     void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.tag == "Ground")
         {
             isGrounded = true;
             jumpState = 0;
         }
     }
     void OnCollisionExit(Collision collision)
     {
         if(collision.gameObject.tag == "Ground")
             isGrounded = false;
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Getting a navmeshagent back on a navmesh. 1 Answer

Dynamically Fixing NavMeshAgent Base Offset? 1 Answer

Navmesh ,jump from door to door. 0 Answers

Enable/Disable the NavmeshAgent programatically? 2 Answers

Failed to create agent because it is not close enough to the NavMesh 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges