Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jul 15, 2019 at 11:25 PM by nubbinownz for the following reason:

Going to rephrase question with some updated info

avatar image
0
Question by nubbinownz · Jul 15, 2019 at 04:40 PM · collisionnavmeshnavmeshagentclipping

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

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.

The enemy code looks like this

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEditor;
 using UnityEngine;
 using UnityEngine.AI;
 
 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 the hitbox code looks like this

 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);
         }
     }
 }

Any ideas would be greatly appreciated. I've been messing with this for a while and just can't figure it out.

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

  • Sort: 

Follow this Question

Answers Answers and Comments

166 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

Related Questions

Navmesh y-axis 1 Answer

Navmesh agent got fused in very crowded situation when colliding. 0 Answers

How do I get NavMeshAgents not to walk through objects? 3 Answers

Navmesh sometimes falling through world when enabled 0 Answers

NPC's bump into eachother trying to reach a position 1 Answer


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