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 /
avatar image
0
Question by zachypin · Jun 21, 2011 at 09:01 PM · rotationgameobjectrotate

Rotate GameObject Issue

So I have a gameobject that I currently have locked onto another object. It's setup with the following code:

 var objectToFollow;
 
 function Update () 
 {
     if(gameObject.Find("localPlayer")==null)
     {}
     else
     {
         objectToFollow = GameObject.FindWithTag("Player").transform;
         transform.position = objectToFollow.TransformDirection(Vector3.forward * 4) + objectToFollow.position;
         transform.rotation = objectToFollow.rotation;
         
         //needs to be rotated by 0,-90,90
         
     }
 }

So the problem I have, as seen by the comment, is that the object needs to be rotated. I've tried a few methods of doing this but they don't work for a specific reason. I need the object to stay in rotation relation to the player. It currently does this with the code, but it's facing the wrong way. I can set it up so that on start of gameplay it's facing the right way, but if I turn it stays pointing the same direction in the world instead of continuing to point at me. This is because the object is a child of my avatar, as it needs to remain.

Any ideas? Thanks!

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

1 Reply

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

Answer by ckfinite · Jun 21, 2011 at 09:04 PM

Didn't I anwser this originally? Anyway, try this:

 var objectToFollow;
 
 function Update () 
 {
     if(gameObject.Find("localPlayer")==null)
     {}
     else
     {
         objectToFollow = GameObject.FindWithTag("Player").transform;
         transform.position = objectToFollow.TransformDirection(Vector3.forward * 4) + objectToFollow.position;
         transform.rotation = objectToFollow.rotation * Quaternion.Euler(0,-90,90);
     }
 }
Comment
Add comment · Show 4 · 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 zachypin · Jun 21, 2011 at 09:17 PM 0
Share

Yup you did, different application atm.

But question about this. Is there any reason this script would cause On$$anonymous$$ouseDown() to not work? I have this code:

void Start () {renderer.material.color = Color.blue; } void On$$anonymous$$ouseDown() {renderer.material.color = Color.green;}

attached to a child of the object with the code you've scripted in the answer. The object renders blue but not green on click.

avatar image ckfinite · Jun 21, 2011 at 09:20 PM 0
Share

No, this script doesn't do anything related to color.

avatar image ckfinite · Jun 21, 2011 at 09:23 PM 0
Share

Also, it works fine in my test scene.

avatar image zachypin · Jun 21, 2011 at 10:18 PM 0
Share

Yeah it works great. I forgot that I deleted my mesh collider to solve an earlier issue so that's why the function didn't work -_- good to go now, thanks!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotation is jumpy 2 Answers

How get the rotation of an GameObject? 3 Answers

Rotate around a locally tilted axis?, 1 Answer

How do I rotate an object a certain number of degrees? 2 Answers

Cannot rotate GameObject from C# Animator attached 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