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 /
  • Help Room /
avatar image
-1
Question by Sayain Gamer · Apr 21, 2016 at 09:16 AM · 2d game2d-physics2d rotationrotaion

Enemy Ai Rotation not working properly

Basically what happens when I got to the corner of my screen the y rotation goes to 180 and i can't see the enemy as the game is 2d. This is my script.

 public class Get_Player : MonoBehaviour {
 
     public float Speed;
     public Transform target;
 
     // Use this for initialization
     void Start () {
         target = GameObject.FindGameObjectWithTag ("Player").transform;
     }
     
     // Update is called once per frame
     void Update () {
         Vector3 dir = target.position - transform.position;
         transform.LookAt (target.position);
         transform.Rotate (new Vector3 (0, -180, 0), Space.Self);
 
         if (Vector3.Distance (transform.position, target.position) > 0f) {
             transform.Translate (new Vector3 (Speed * Time.deltaTime, 0, 0));
         }
     
     }
 }

Comment
Add comment · Show 6
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 Sayain Gamer · Apr 21, 2016 at 08:52 AM 0
Share

sorry it should be -90 not -180.

avatar image Immanuel-Scholz Sayain Gamer · Apr 21, 2016 at 09:25 AM 0
Share

You can edit your own posts to fix mistakes and clarify things, you know? ;)

Things to clarify: Who is getting to the corner? The player or the object controlled by this script?

Also, why do you rotate around y anyway there? looks strange..

avatar image Sayain Gamer · Apr 21, 2016 at 08:53 AM 0
Share

but it still doesn't work.

avatar image jmparavicini · Apr 21, 2016 at 09:24 AM 0
Share

I'm not entirely sure what you are trying to accomplish but what i see is that you call transform.LookAt and transform.Rotate in every frame this will lead to unexpected results. If you can explain a little bit more what you are trying to do I can maybe help a little bit more ;P.

avatar image Immanuel-Scholz jmparavicini · Apr 21, 2016 at 11:06 AM 0
Share

call transform.LookAt and transform.Rotate in every frame this will lead to unexpected results

Sorry? There is nothing wrong with changing a transform rotation via different methods multiple times in a frame and every frame.

What are the unexpected results you are talking about? I am not aware of any hickup in Unity regarding to changing transform properties every frame (or even more often).

avatar image Ryanless Immanuel-Scholz · Apr 21, 2016 at 02:19 PM 0
Share

When he says unexpected results, he doesnt mean that unity has a problem doing that. But that the programmer usally has no clue what the result is, but very likely not the desired one.

So having just 1 way of changing helps you - as the programmer to understand what actually is happening - which in return helps a lot in making the script behave as you want. ;-)

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how can i anchor a point of a sprite to make it swing? 1 Answer

scale a value 0 Answers

2D player enter/exit orbit 0 Answers

Unity 2d C# - Orbit object around another objects center using mouse position 0 Answers

Unity 2D- How to role a polygon? 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