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 Josenifftodd · Nov 29, 2014 at 11:43 PM · aienemyrotatingwrong

Rotating Wrong

when the AI moves towards me it rotates forward for some reason, same as when it sees my player if I move it'll tilt the model forward a little and then when he chases me it doesn't work very well it just stays where it rotated to and ends up flipping everywhere, Ive added a ridgidbody.. but it still hasn't worked. Is they a way I can make it not rotate? I've froze the rotation using the ridgidbody.

My code is below.

 var Distance;
 var Target : Transform;
 var lookAtDistance = 25.0;
 var attackRange  = 15.0;
 var moveSpeed = 5.0;
 var Daping = 6.0;
 var myTrans : Transform;
 
 
 private var anim : Animator;
 
 function Start () {
         anim = GetComponent(Animator);
 }
 
 function Update () 
 {
             Distance = Vector3.Distance(Target.position, transform.position);
             if (Distance < lookAtDistance) 
             {
                 anim.SetBool("Walking", false);
                 Debug.Log("Looking at Player!");
                 lookat ();
                 
             }
             
             if (Distance > lookAtDistance)
             {    
                 Debug.Log("Looking For Player!");
                 
             }
             
             if (Distance < attackRange)
             
             {
                 transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
                 //anim.SetBool("Walking", true);
                 Debug.Log("Attacking");
             }
             
             
 }
 
 function lookat () {
     var rotation = Quaternion.LookRotation(Target.position - transform.position);
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Daping);
 }
 
 function attackPlayer () {
     //transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
 }
 

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 theLucre · Nov 30, 2014 at 02:03 AM

You're pointing the object at the target transform in the lookat() method. Remove that code and it shouldn't never rotate at all.

Comment
Add comment · Show 2 · 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 Josenifftodd · Nov 30, 2014 at 02:18 PM 0
Share

This line?

 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Daping);
avatar image Josenifftodd · Nov 30, 2014 at 03:24 PM 0
Share

When I remove the code above it walks off in a different direction, I put + ins$$anonymous$$d of $$anonymous$$us and it runs away from my player doing the weird rotating thing, I've attached a image of what I'm on about as I don't feel I've explained it in good enough depth for anyone to understand my problem. I got the AI working before but lost code as had to reformat haven't a clue why it's being an idiot. Starting to dislike Unity to be fair :/alt text

rotatewrong.png (120.1 kB)

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

27 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

Related Questions

How to reach multiple GameObjects' value , enemy AI 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Enemy AI C# 0 Answers

Enemy Avoid Terrain 0 Answers

I am making an AI Script and i need to find out how to make the enemy move in random x and z axis movements(Random!!!)This script works, but the movement is never ending. 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