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 abi-kr01 · Mar 26, 2014 at 01:13 PM · rotationlookatfollowlimit

rotate gameobject

i have 2 gameobject "TanHead" and plane(with position increment in x ) ,what i want is my TanHead to follow plane with only rotation ,position of Tank is fixed .so when my gameobject (plane) is above Tank the rotation on TanHead will be 270 degree. i have looked and tried lookat function but i cant use that because i want to fix tank rotation upto 0 to 90 degree

here is my my image alt text

here is what it should look like when my plane goes by alt text

now what m using for rotation

 var target : Transform;
 var myself:Transform;
  
 var tempAngle:float;
 
 
 
 private var angle: Vector3 = new Vector3(360,270,0);
 @script AddComponentMenu("Camera-Control/Smooth Look At")
 
 
 
 
 
 function LateUpdate()
 {
 myself.LookAt(target);
         if(myself.transform.rotation.x != 0)  
         //seem to get a 0 if my target is in
     //certain places because I am using a mouse pos and hit with plane.
         {
             tempAngle = myself.transform.rotation.x * 100; //don't know how to read a euler
     //angle into a float so I just multiplied by 100 to get the angle.
         }
         else
         {
             tempAngle = tempAngle;
         }
          myself.rotation = Quaternion.Euler(tempAngle,270,0);
     
     
     
     
 }





what i can do to fix it because with this script when my plane goes to 270 degree it direct it self to 360 degree causing big jerk thank you

after.png (237.8 kB)
start .png (242.1 kB)
Comment
Add comment · Show 5
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 diegzumillo · Mar 26, 2014 at 01:40 PM 0
Share

It depends on what you want it to happen after this angle. Does it stop rotating at all or does it flip to the other side?

avatar image trololo · Mar 26, 2014 at 01:44 PM 0
Share

Well just don't do the call to LookAt() function if headTank.transform.localRotation.eulerAngles.x > 90.

avatar image abi-kr01 · Mar 26, 2014 at 02:06 PM 0
Share

diegzumillo i want it to go back to its previous position after it reaches its limit with smooth rotation

avatar image robertbu · Mar 26, 2014 at 02:37 PM 0
Share

2D or 3D and what is 'previous position'?

avatar image Forest_San · Mar 27, 2014 at 01:32 AM 0
Share

Is the angle can't setting by you want? $$anonymous$$aybe you can see following Quesstion that Proposed by me.link text

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nodgez · Mar 26, 2014 at 02:49 PM

     void Aim()
     {
         Vector3 direction = Vector3.Normalize(targetTransform.position - transform.position);
         float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg;
         Quaternion rotation = Quaternion.AngleAxis(angle,Vector3.forward);
         transform.localRotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime);
     }

This is what I think you want. Attach it to the TanHead. You might need to change the Pivot point of your sprite to get the effect right. you find the direction you need to look and then use the Atan2 function to rotate to it in 2 Dimensions.

If you want the TanHead to follow the gameobject precisely then remove the Quaterion.Slerp() function and just set it to the rotation variable. you might also want to use Mathf.Clamp() on the angle but that is up to you.

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

23 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

Related Questions

LookAt Limit Up and Down rotation only 2 Answers

Camera following/looking at aircraft 1 Answer

Add rotation to LookAt (CarSmoothFollow) ? 1 Answer

Bones [or something] to 'follow' or 'chase' each other! 1 Answer

how to limit rotation 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