Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 nubbinownz · Jul 15, 2019 at 11:30 PM · collisiongameobjectcollidernavmeshnavmeshagent

Navmesh sometimes falling through world when enabled

So this one is baffling me. Right now I have a simple navmesh agent setup to track the player and just walk towards him. When the enemy is hit a small knockback force is applied, the enemy stops moving and the navmesh agent is disabled, once a timer counts down the navmesh reenables to follow the player. Before I used navmesh, I was just doing a basic rigidbody.velocity movement towards the player and it worked just fine ( with the exception of not being able to avoid objects)

Now with the navmesh agent going, every once and a while when I hit the enemy, it gets BLASTED through the floor on the first hit and flies off into space under the world(they should be able to take about 5 hits before they destroy)

then obviously they can't turn their navmesh back on because they are somewhere 1000 miles below the world lol.

I can't figure it out. I've tried changing when the navmesh disables, I've put the code in the hit box, before the add force, after the add force and it always does the same thing.

Here is a gif of what is happening

https://i.imgur.com/hNhRAHC.gifv

The "intended" behavior is that they get hit> stop moving> knocked back. They have 100 HP and each hit does 15 damage.

What you are seeing when they immediately disappear is them flying through the ground.

From what I can gather, it has something to do with navmesh stopping. I've tried updatePosition as well and the same thing happens.

Here is the enemy code

 public class Enemy : MonoBehaviour
 {
     public Transform target;
     private Transform player;
     private Rigidbody rb;
     public float spd;
     public bool isHit;
     private float hitStun;
     public float hitTimer = 1;
     public float hp;
     public NavMeshAgent agent;
  
     // Start is called before the first frame update
     void Start()
     {
         agent = GetComponent<NavMeshAgent>();
         rb = GetComponent<Rigidbody>();
  
         player = GameObject.Find("Player").transform;
  
         target = player;
     }
  
     // Update is called once per frame
     void Update()
     {
         if (isHit && Time.time > hitStun)
         {
             isHit = false;
         }
  
         if (hp <= 0)
         {
             Destroy(gameObject);
         }
     }
  
     private void OnTriggerEnter(Collider other)
     {
         if (other.CompareTag("Weapon"))
         {
             hitStun = Time.time + hitTimer;
             isHit = true;
         }
     }
  
     private void FixedUpdate()
     {
         if (!isHit)
         {
             agent.enabled = true;
             if (agent.enabled)
             {
                 agent.destination = target.transform.position;
             }
         }
     }
  
     public void TakeDamage(float dmg)
     {
         hp -= dmg;
     }
 }

and here is the hit box code that uses the trigger to hit the enemy

 public class hitBox : MonoBehaviour
 {
     public float knockback;
     private Rigidbody rb;
  
     public Transform playerPos;
     private Enemy enemy;
  
     public float dmg;
  
  
     // Start is called before the first frame update
     void Start()
     {
     }
  
     // Update is called once per frame
     void Update()
     {
     }
  
     private void OnTriggerEnter(Collider other)
     {
         if (other.CompareTag("Enemy"))
         {
             enemy = other.GetComponent<Enemy>();
             rb = other.GetComponent<Rigidbody>();
             Vector3 direction = (other.transform.position - playerPos.position).normalized;
             enemy.agent.enabled = false;
             enemy.TakeDamage(dmg);
             rb.AddForce(new Vector3(direction.x, 0, 0) * knockback);
         }
     }
 }


I've tried everything I can think of. I noticed if I set the enemy spawner higher into the air, the enemies slam into the ground upon spawning, so it looks like they aren't using normal gravity, just snapping to the terrain. I am wondering if that might have something to do with it.

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

218 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i check if GO collided with collider starting with name (string) 1 Answer

How can I have an enemy be able to fall through a Navmesh? 0 Answers

GameObjects glitching through other Objects when being held 0 Answers

Enemy Object sometimes falls through floor on hit, only with Navmesh 0 Answers

Gameobject collision with Terrain C# 4 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