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 /
This question was closed Apr 24, 2017 at 09:53 AM by omerselman for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by omerselman · Apr 22, 2017 at 01:05 AM · rotate objectrotation axislookrotationy-axisx-axis

LookRotation freaks out..

hello everyone, I have a tank which has 3 moving parts. First one is the tank itself, which shall look to target and it does perfectly. Second one is the turret which shall look to target and it does perfectly. Third one is the barrel and damn barrel suppose to look to target but it does not. tank and turret rotates on Y Axis, barrel suppose to rotate on X axis. I tried several ways but all failed. tried to clamp rotation of other axises but failed. tried to use turrets Y and Z axis because barrel is child of the turret and failed again. it is so weird that same code doesnt work for pitch rotate. let me show you what i tried already..

    var lookPos = Target.transform.position - barrel.transform.position;
             lookPos.x = 0;
             var rotation = Quaternion.LookRotation(lookPos);
             barrel.transform.rotation = Quaternion.Slerp(barrrel.transform.rotation, rotation, Time.deltaTime * RotationSpeed);

                 Vector3 targetPostition = new Vector3(barrel.transform.position.x, Target.transform.position.y, Target.transform.position.z);
                 barrel.transform.LookAt(targetPostition);

both methods above failed. Turret is child of tank and barrel is child of turret. The most successfull aproach was

 barrel.transform.LookAt(Target.transform.position);

which is useless for me because it moves faster than turret and i dont want barrel to move around by itself. What i want? I want tank and turret to rotate to target on Y axis only and barrel to rotate on X axis only in individiual speeds. Thank you for your time..

edit : second code removed target.x and added barrel.x

Comment
Add comment · Show 1
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 omerselman · Apr 24, 2017 at 09:53 AM 0
Share

Edit 2 : for those who need correct answer is given in the link below. tagging subject as answered. http://answers.unity3d.com/questions/388185/make-the-turret-automatically-rotate-to-look-at-wh.html

2 Replies

  • Sort: 
avatar image
0

Answer by Commoble · Apr 22, 2017 at 01:14 AM

The first thing I see that you're doing wrong is that you're using Slerp wrong.

Slerp (and other Lerp-like functions) take in three values: A, B, and T, where A and B are anything and T is in the range [0,1]. It returns a value between A and B based on T: if T is 0, then it returns A. If T is 1, then it returns B. If T is between 0 and 1, then it returns a corresponding value between A and B.

Calling Time.deltaTime returns the amount of time (in seconds) the previous frame lasted; if you don't have any performance problems, it's typically roughly 1/60th of a second (around 0.0167F).

Multiplying Time.deltaTime by your speed variable and using the result as your T-value in Lerp or Slerp is virtually never useful. The usual way to use Lerp and Slerp is to gradually change your T-value from 0 to 1 over the course of many Update events (or in a coroutine) so that your rotation or position starts at one value at one time and ends at another value at another time.

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
avatar image
0

Answer by omerselman · Apr 23, 2017 at 11:40 AM

http://answers.unity3d.com/questions/36255/lookat-to-only-rotate-on-y-axis-how.html those codes are actually working well for Y axis but not for X axis...

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

More specific Quaternion.LookRotation 1 Answer

How to stop a Gameobject moving on the X axis 1 Answer

Rotate a gameobject by a specific angle and stop when character doesnt move anymore 0 Answers

Child of a gameobject lookAt only around Y-axys 1 Answer

Why is this rotation not performed as expected? 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