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 /
avatar image
0
Question by KreativeDoggo · Oct 18, 2019 at 03:00 PM · programmingnavmeshagenttracking

why does collider data-type null itself?

i have a game-object (enemy = E) and two player-objects (P1 & P2). when leftclicking on a player-object and then rightclicking on a location on the ground-plane in the scene a marker is placed and the player moves to the set position,

E has a sphere-collider marked as trigger on it. when a player-object enters the trigger, the collider data-type is stored and the entered player becomes a target for E to focus on, i've tried to set it up in such a way that if P1 enters the zone first, then E will ignore P2 until P1 is dead, or leaves using a on-trigger exit.

now here comes my strange experience, if P1 enters the zone, and then collides with the box-collider that E has, then the collider-data that lets E locate P1 becomes null,

the problem with this is esentialyy that it would the player to simply ram their enemies to imobilize them, a cool ability but not something that should be a default feature.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 
 public class EnemyController : MonoBehaviour
 {
 
     public float MeleeRange = 5;
     public float AttackStrength = 15;
     public float EnemyShield = 50;
     public float EnemyHealth = 400;
 
     private Collider EnemyTarget;
     public NavMeshAgent Agent;
     private Vector3 EnemyTargetDestination;
 
     private void Update()
     {
         if(EnemyTarget != null)
         {
             EnemyTargetDestination = EnemyTarget.transform.position;
             SetTargetAsDestination();
         }
         else
         {
             Debug.Log("no target");
         }
 
         if(EnemyHealth <= 0f)
         {
             Destroy(gameObject);
         }
     }
 
 
     private void OnTriggerEnter(Collider other)
     {
         if (EnemyTarget == null)
         {
             if (other.tag == "Player")
             {
                 Debug.Log("player entered range");
                 EnemyTarget = other;
             }
         }
     }
 
     private void OnTriggerExit(Collider other)
     {
         if(EnemyTarget.gameObject.name == other.gameObject.name)
         {
             EnemyTarget = null;
             EnemyTargetDestination = transform.position;
         }
     }
 
     private void SetTargetAsDestination()
     {
         if (Vector3.Distance(transform.position, EnemyTargetDestination) >= MeleeRange)
         {
             Agent.SetDestination(EnemyTargetDestination);
             Agent.isStopped = false;
         }
         if (Vector3.Distance(transform.position, EnemyTargetDestination) <= MeleeRange)
         {
             Agent.SetDestination(transform.position);
             DamageTarget();
         }
         transform.LookAt(EnemyTargetDestination);
   
     }
 
     private void DamageTarget()
     { 
     
             EnemyTarget.GetComponent<StatController>().TakeDamage(AttackStrength * Time.deltaTime);
             Debug.Log("Target health = " + EnemyTarget.GetComponent<StatController>().CharacterHealth);
     }
 
     public void TakeDamage(float damage)
     {
         EnemyHealth = EnemyHealth - (damage / ((EnemyShield + 100) / 100));
     }
 }
 

upon collision between P1 and E, P1 can step away by a unit or so, and then E.target == null, if P1 and E then come into contact again, P1 will become the target of E as long as they touch, and then E.target becomes null if P1 steps away again....

here is some screen-capture of the behaviour.

https://vimeo.com/367278329

EDIT: I've tried the same thing, but disabling the smaller box-collider, the box-collider does not affect the situation.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KreativeDoggo · Oct 18, 2019 at 03:56 PM

Problem have been solved, there was a child-object wiht a collider marked as trigger. this would react to the onTrigger functions.

Comment
Add comment · Share
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

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

127 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

Related Questions

Multiple Cars not working 1 Answer

NavMeshAgent CalculatePath to SetPath ( Agent new Path, SetPath, initiatePath?)??? 0 Answers

Basic Mind Control Mechanic 1 Answer

Retention distance of enemy relative player 0 Answers

How to track user's speed and distance using GPS in Unity? 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