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 TheEmeraldRuby · Jun 12, 2018 at 08:06 PM · facinglockon

How to make a gameobject always face towards another? (tidally locked)

Hello, everyone. The title explains it all. How would I make an object always facing towards another object (like the Moon always faces the Earth)? All the methods I found were outdated and don't work anymore. Thanks for your help!

Comment
Add comment · Show 3
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 bakir-omarov · Jun 12, 2018 at 08:08 PM 0
Share

Are you using 2d?

avatar image TheEmeraldRuby bakir-omarov · Jun 12, 2018 at 08:09 PM 0
Share

No, I'm using 3D.

avatar image Cherno · Jun 12, 2018 at 08:10 PM 0
Share

Transform.LookAt?

2 Replies

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

Answer by bakir-omarov · Jun 12, 2018 at 08:14 PM

It is first what is pops on my mind:
p.s - guys check this little Lego Batman passing near cubes, omg so cute! alt text


 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour
 {
     public GameObject Moon;
     public GameObject Sun;
 
     void Update()
     {
         // Rotate the camera every frame so it keeps looking at the target
         Moon.transform.LookAt(Sun.transform);
         Sun.transform.LookAt(Moon.transform);
     }
 }



unity-funny-lookat2.gif (507.7 kB)
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
1

Answer by ALinnear · Jun 12, 2018 at 08:20 PM

You can try using RotateTowards.

In your code you can create a public GameObject target or make it a public Transform target. Also make a game object for the one that seeks a position/rotation to face like public GameObject moon. Then in an Update() method you would write something like this: moon.Transform.rotation=Quaternion.RotateTowards(moon.Transform.rotation,target.Transform.rotation,float time) where here the method uses the original rotation of your Moon or whatever you want to rotate, and it rotates towards the target which can be your Earth. In the inspector you'll need to drag and drop in the appropriate gameobjects/prefabs.

This is just a guess, I haven't ran any code yet to back up my answer; give it a shot and see what happens @TheEmeraldRuby .

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

86 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

Related Questions

rotating to the current facing position 2 Answers

How do you get your character to look the way you are walking? 1 Answer

How do I fire a bullet where my player is facing? (C# 2D) 2 Answers

Lock On and Unlocking [3D] 2 Answers

Look rotation facing vector zero 5 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