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 TheShadyColombian · Aug 16, 2014 at 10:52 PM · blenderenemyfollow.obj

Enemy not following player.

If you've seen my previous answer, this is sort of a followup on a different subject. I have a character (enemy) made in Blender and exported each individual mesh into a separate .obj file. after doing this, the enemy no longer follows the player. Here is my script:

 using UnityEngine;
 using System.Collections;
 
 public class ExperimentalEnemy : MonoBehaviour {
 
         public Transform target; 
         public int moveSpeed; 
         public int rotationSpeed; 
         public float noChaseRange = 50f;
         public int HitBoxRadius;
         public ExperimentalDeath Damage;
         public float Health = 10f;
         private Transform myTransform;
         public GameObject Char;
         public Animator EnemyAnim;
         public GameObject Poof;
         public bool isDead;
         void Awake() {
             myTransform = transform;
         }
         
         // Use this for initialization
         void Start () {
             GameObject go = GameObject.FindGameObjectWithTag("Player");
             
             target = go.transform;
 
             isDead = false;
 
             Char = GameObject.FindGameObjectWithTag("Player");
 
             HitBoxRadius = 4;
 
             
 
 
         //Reference to DamageChar from the ExperimentalDeath.cs script
         Component Damage = Char.GetComponent<ExperimentalDeath>();
 
     }
     
     // Update is called once per frame
         void Update () {
             if (Health < 0.1) {    
 
                 isDead = true;
 
                 EnemyDie ();
             }
             Debug.DrawLine(target.position, myTransform.position, Color.blue);
 
             if (isDead == true){
 
                 Health = 0F;
 
                 Destroy (collider);
 
                 if(Random.Range(0f, 20f)< 1){
 
                     Instantiate (Poof, transform.position, transform.rotation);
 
                 }
 
             }
             
             if (isDead != true){
 
                 //Look at target
 
 
                 transform.LookAt(target.position);
 
 
                 if(Vector3.Distance(target.position, myTransform.position) > noChaseRange) {
                     //Move towards target    
 
                     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
                 }
                 
                 if(Vector3.Distance(target.position, myTransform.position) < HitBoxRadius) {
                     Damage.DamageChar(Random.Range(0.01F, 0.2F));
                     Debug.Log ("Is Damaging " + Char);
                 }
             }
 
         }
  
     public void EnemyDamage (float amount) {
         Health -= amount;
     }
 
     public void EnemyDie () {
 
         //if(Random.Range(0f, 10f)< 1){
         //}
             Destroy (gameObject, 2F);
             EnemyAnim.SetBool ("Die", true);
     }
 
     void OnTriggerEnter (Collider other){
         if (other.gameObject == GameObject.FindGameObjectWithTag ("Bullet")){
             Destroy (other, 0.1F);
             EnemyDamage(Random.Range(0.1F, 0.2F));
         }
     }
 
 }

Comment
Add comment · Show 3
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
avatar image Cherno · Aug 17, 2014 at 01:39 AM 0
Share

What do you mean by "exported each individual mesh"? How many meshes does your enemy have? Is there animation involved? Are there any error messages? Have your tried inserting Debug.Log lines to check where exactly the script is not working as intended?

avatar image TheShadyColombian · Aug 17, 2014 at 05:15 PM 0
Share

there is a mesh for each body part (head, chest, legs x2 and arms x2) as a pose to exporting the whole thing as a blender file. my enemy follows the player and when near enough, goes into the player's script and calls for damageChar which subtracts health from the player

avatar image TheShadyColombian · Aug 17, 2014 at 08:35 PM 0
Share

I noticed that the problem is the animation. when i disable the animator the character moves fine (but the poof gameObject doesn't appear for some reason). i tried deleting all of the frame keys but it still didn't move. i (obviously) need the animation for the game sooooo..

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by dvora · Aug 17, 2014 at 10:32 PM

you can create a single parent for all the meshes and use the: transform.position=Vector3.MoveTowards(transform.position,target.position, speed);

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
avatar image
0

Answer by TheShadyColombian · Aug 17, 2014 at 10:03 PM

i Fixed it! (yayyy!!!!) to fix it, i duplicated the empty that all the meshes are parented to and has all the components, and i parented it to the duplicate. for the one parented to the duplicate, remove every component but the animator, and the root one, keep everything but the animator. i still have one problem; the blootSplatter object and Poof object don't appear. (can i post this as an answer, BTW?)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enemy Targetting Help 1 Answer

Enemy Follow Issue 3 Answers

Enemy Script 2 Answers

make enemy attack 0 Answers

Script to make an enemy follow the player when they trigger a door? 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