• 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 W1k3 · Jan 24, 2014 at 10:52 PM · rotationmovementphysicscolider

Look at script wrong at high speeds

I've tried numbers of look at scripts, but whenever they get to a $$anonymous$$gh speed, they are always a little offset. It's hard to explain, so I made 2 .gifs so you can see.

The enemy s$$anonymous$$p follows you and turns to face you. when it is $$anonymous$$t by a projectile, it stops. Once the linecast coming off the enemy $$anonymous$$ts the player, it resumes looking at the player.

http://i.imgur.com/hTxAJpG.gif

But if the enemy moves at a $$anonymous$$gh speed, it gets offset. I've noticed t$$anonymous$$s problem allot in unity, but in t$$anonymous$$s game I can't let it slide as easily.

http://i.imgur.com/bjz8kKg.gif

Here are some scripts I have used:

          var newRotation = Quaternion.LookRotation(transform.position - target.position, Vector3.back);
  
          newRotation.x = 0.0f;
  
          newRotation.y = 0.0f;
  
          transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * rotatespeed);

(currently using that one ^^^)

      var dir = transform.position - target.position;
      var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
      var newRotation = Quaternion.AngleAxis(angle, Vector3.forward);
      transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * rotatespeed);

,

     rigidbody2D.transform.eulerAngles = new Vector3(0,0,Mathf.Atan2((TARGETTRANSFORM.position.y - transform.position.y), (TARGETTRANSFORM.position.x - transform.position.x))*Mathf.Rad2Deg - 90);


I tried all these scripts and noticed no difference. I have tried using 3D and 2D colliders (currently using 2D) and have found no difference. I tried using the Update, LateUpdate, and FixedUpdate. W$$anonymous$$le fixed update is the smoothest, it doesn't fix the problem.

If there is some way to refresh the looking script, or get it to be more accurate (preferably with an adjustable speed), that would be fantastic.

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 njpatter · Jan 24, 2014 at 10:56 PM 1
Share

When it happens and is running, could you hit Pause and then check the scene view?

I am wondering if the collisions are hitting one of the ships out of the plane they are on. This coupled with a perspective camera could give you the look of an offset when it actually is looking right at it.

avatar image W1k3 · Jan 25, 2014 at 06:57 AM 0
Share

Sorry for the late reply.

It doesn't seem to be looking at it from a perceptive either.

alt text

1.jpg (44.2 kB)
2.jpg (37.9 kB)
avatar image W1k3 · Jan 25, 2014 at 07:01 AM 0
Share

Do you think it's possible to cap how fast the enemy rotates? That way if I came up with a number for when it messes up, it could be prevented.

avatar image Benproductions1 · Jan 25, 2014 at 07:07 AM 0
Share

You shouldn't ever be setting any part of a quaternion to any value unless you know what you are doing. A Quaternion is made up of x, y, z, and w. None of them have anything to do with the dimensions of space.

Have you tried just setting the forward vector of the ship?

 transform.forward = (transform.position - target.position).normalized;
avatar image getyour411 · Jan 25, 2014 at 07:07 AM 0
Share

To the question about cap, absolutely - look at Mathf.Clamp. Otherwise, I'm useless with rotation questions.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Rotating my character only while moving in a 2D plane 3 Answers

Rotation used as movement 4 Answers

Quadcopter moving downward because of tilting. How to make it move without changing y axis velocity when presing WASD? 3 Answers

How not to make a RigidBody not go into ground when tilted foward? 1 Answer

How to make a RigidBody not go into ground when tilted foward? 2 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