Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
This question was closed Sep 01, 2021 at 09:15 AM by Cravenburg for the following reason:

I have found the answer from the internet to my question .

avatar image
0
Question by Cravenburg · Sep 01, 2021 at 01:43 PM · modelanimator controllerblender-exportingai problems

Enemy model , AI and animation is not working properly

So hi guys , i am just learning unity and and is running into a bunch and by that i mean a bunch of problems. First of all my enemy character completely loses its shape when i make a humanoid rig out of it so when i use lookat function with generic rig , his whole body turns up and down . He even faces the opposite way when using lookat but i did some things and fixed (if u guys have a better solution i can do in either blender or unity to fix it pls tell). Secondly and most important one its animation . I have made a script where it should chase player when in a certain range( 10f ) and thus play the run animation . But i also want it to stop running behind the player when the player is beyond limits and thus change to idle animation . But the distance between enemy and player is stuck at 9.91 or something after 9.5f and the enemy keeps on playing run animation . Please tell me a fix for it . My game is in 3D .

Enemy Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 
 public class EnemyCOntroller : MonoBehaviour
 {
     public float lookRadius = 15f;
     NavMeshAgent agent;
     Transform target;
     float distance;
     private Animator animator;
     private float horizontalInput;
     private float attackRAnge = 7f;
 
     // Start is called before the first frame update
     void Start()
     {
         target = PlayerManager.instance.player.transform;
         agent = GetComponent<NavMeshAgent>();
         animator = GetComponent<Animator>();
        
     }
 
     // Update is called once per frame
     void Update()
     {
         horizontalInput = Input.GetAxis("Horizontal");
         distance = Vector3.Distance(target.position, transform.position);
         attackRAnge = Vector3.Distance(target.position, transform.position);
         if (distance <= lookRadius)
         {
             agent.SetDestination(target.position);
             animator.SetFloat("Run", attackRAnge) ;
             
             FaceTarget();
         }
         else
         {
             
         }
         
         if (distance <= 7f)
         {
 
             agent.SetDestination(transform.position);
 
         }
         
 
         animator.SetFloat("Attack", attackRAnge);
     }
     
    
 
 
     void FaceTarget()
     {
 
         transform.LookAt(2 * transform.position - target.position);
 
 
     }
 
 
     private void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawWireSphere(transform.position, lookRadius);
     }
 
     
 
 
 }
 






alt text

alt text

screenshot-40-min.png (235.4 kB)
screenshot-41-min.png (292.1 kB)
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

2 Replies

  • Sort: 
avatar image
1

Answer by Riiich · Sep 01, 2021 at 08:19 AM

Split your questions into separate questions so it's easier for us to understand.

  1. With the first question, can you show a video of exactly what happens when the model goes crazy. I think a part of the LookAt issue is you're doing it on the whole model, not just the head - but if this is correct, I think you need to Google how LookAt works

  2. Go through your code step by step, make debug.log() bits so you see exactly what's happening when running away

Comment
Add comment · Show 1 · 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 Cravenburg · Sep 01, 2021 at 09:02 AM 0
Share

added a second image for your reference and im new to unity so idk how to make the head only move towards the object and i cant find anything on the net .

avatar image
0

Answer by Cravenburg · Sep 01, 2021 at 08:09 AM

Can somebody help?

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

Follow this Question

Answers Answers and Comments

129 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

Related Questions

Blender Model Export To Unity 1 Answer

Importing joint objects from Blender - default rotation and scale values 0 Answers

How to apply my selfmade UV Maps properly in Unity? 1 Answer

Foot twisting in when walking 0 Answers

FBX Importing incorrectly from blender to unity 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