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
0
Question by SamTam · Jan 14, 2017 at 02:03 PM · rotationaxisturretlookrotation

Turret rotating on a z axis

Hello all. I'm trying to make a game. And i wan't to know how can i make a turret rotate to the nearest enemy but on the z axis. I have made the same code like the tutorial on Brackeys about "Tower Defence ("Turrets")":

https://www.youtube.com/watch?v=QKhn2kl9_8I&t=1347s.

But at his code it say's : Vector3 rotation = lookRotation.eulerAngles; transform.rotation = Quaternion.Euler(0f, rotation.y, 0f);

So i replaced the "y" with a "z" like so : transform.rotation = Quaternion.Euler(0, rotation.z, 0); but it doesn't work. I've tried switching them but it doesn't work.

Please help me.

Thank's.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ownerfate · Jan 14, 2017 at 05:30 PM

I may know why it might not work.

but there is my script for my character's arm to rotate on the Z axis, you'll have to do some fanegling, to get it to work.

code:

      function LateUpdate ()// this is unchanged from my script.
         {
         rotationZ += Input.GetAxis("Mouse Y") * sensitivityZ;
         rotationZ = Mathf.Clamp (rotationZ, minimumZ, maximumZ);
         transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y,rotationZ);
         }
 

judging by mine, while looking at yours, my script doesn't use Quaternions, but this script has a clamp so it won't do 360, but, removing the (Clamp) middle line of code, with the 2 lines left, will probably be what you're looking for.

take what you need from this, and see what happens, and switch what you need to switch to make it work.

give it a shot.

hope that helped.

Comment
Add comment · Show 9 · 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 SamTam · Jan 16, 2017 at 09:51 AM 0
Share

Thanks so much! I will try.

avatar image ownerfate SamTam · Jan 16, 2017 at 10:14 AM 0
Share

[ anytime ]

avatar image SamTam ownerfate · Jan 16, 2017 at 10:35 AM 0
Share

I asked this question because i'm making a 2d space shooter game. And i want to attach a turret to my spaceship that will see the nearest enemy and shoot at it.

Show more comments
Show more comments
avatar image
0

Answer by SamTam · Jan 16, 2017 at 11:15 AM

It works great. Thank you so much ownerfate.

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

100 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 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 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 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

3 Axis Camera Rotation 0 Answers

How can I clamp a target rotation within the rotation limits of a character joint? 0 Answers

Turret rotation based on its own local rotation. 3 Answers

Why does RotateTowards rotate in an "orbit" rather than on the spot? Help me understand! 0 Answers

Rotate an object to a position only through one axis 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