• 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 N1warhead · Jan 03, 2015 at 04:11 PM · rotationlookatturret

Rotate Turret to Tag

Hey guys, I'm making a Multiplayer game with Photon networking. Well anyways, I'm not asking for advice on Networking, I can do that part.

What I'm trying to figure out is.

I know there is a Transform.LookAt(Name of Variable);

But that wont work the way I want, as I will have players leaving and joining games all the time.

I really don't want to put in an Update function to keep searching for new players when I know there has to be another way to do this.

I have a trigger zone, with an OnTriggerStay and OnTriggerExit.

Well, I have the tags of "Red" and "Green".

Well, how do I make this turret rotate to a tag that enters if I can't use transform.LookAt?

I need to have the model rotate towards player and have the BARREL rotate up and down just encase enemy is higher or lower than the barrel.

I don't have any code because I can't get anything I try to work at all. I know it's something simple, I just can't quite grasp how to rotate to only a tag that enters into the Trigger Zone.

I want an effect like this. As you can see, I have the top part that rotates left and right and the boxy looking part that lifts the barrel up and down.

alt text

I don't need an ultimate way of doing this, just a hint on what I need to look up to get this to work. As I've always used transform.LookAt. I don't know anything else to use.

turret.jpg (71.3 kB)
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 N1warhead · Jan 03, 2015 at 04:31 PM 0
Share

Thanks buddy! I'll look into this!

1 Reply

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

Answer by Scribe · Jan 03, 2015 at 04:26 PM

You will have to find the closest object of a tag, you could have a list List for red and green that you add to or remove from when a new player enters/leaves your trigger area rather than in update, that would be quite efficient. Then you can loop through that list and find the closest transform, once you have that, you could have a look at my answer or even the code in the question HERE for how to rotate parts on separate axes.

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.

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

26 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

Related Questions

Multiple Cars not working 1 Answer

How to clamp Lookat? 2 Answers

Simple LookAt Rotation with offset pivot 2 Answers

BOX ROTATE ONLY ON X AXIS When Look AT!!HELP! 0 Answers

Simple Script Problem 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