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 AngeloGebauer · Sep 30, 2016 at 01:40 PM · objectrotaterotate objectrotatearound

Rotate object arround other object, but always facing the camera

Hi everyone,

I'm not working long with Unity and i have a problem of how to approach this situation.

What we have in the scene:

  • object1

  • object2

  • camera

What i want to do:

Object1 is a static object, not moving, just sitting there. On the right side of object1 is object2. Object2 should always be next (right side) to object 1. So if the camera moves arround object1, object2 should always rotate arround object1 and from the cameras perspective stay right of object1.

Object2 should also rotate itself to face the camera, but thats not the point of this thread.

Maybe this image can help understanding what i want to do: alt text

Some help would be really nice. Thanks, Angelo

1.jpg (33.5 kB)
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 doublemax · Sep 30, 2016 at 06:40 PM

So the "object 2" should always be perpedicular to the line between "object 1" and the camera?

Try this script, you need to drag the camera and the center object into the respective variables.

The comments should explain what's going on.

 using UnityEngine;
 using System.Collections;
 
 public class Satellite : MonoBehaviour
 {
   public Camera _camera;
   public GameObject _center_object;
   public float _distance = 2.0f;
 
     void Update ()
   {
     // vector from the center-object to the camera
     Vector3 vec = _center_object.transform.position - _camera.transform.position;
 
     // create a vector that's perpedicular to the up vector *and* the vector towards the camera
     // => vector from the center-object to the new satellite position
     Vector3 vec_sphere = Vector3.Cross( vec, _center_object.transform.up );
 
     transform.position = _center_object.transform.position - vec_sphere.normalized * _distance;
     }
 }

Comment
Add comment · Show 1 · 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 AngeloGebauer · Oct 04, 2016 at 08:15 AM 1
Share

Thank you very much!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate an object around one of his childs in the self space (not the world space) 2 Answers

Select next and previous child gameobject on press key 1 Answer

Rotate an Object while moving forward using empty gameObject 0 Answers

Simple Rotate Script won't work! 2 Answers

Rotate object to joystick and position direction 0 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