Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Royall · Jul 28, 2014 at 02:01 AM · rotationfollowtransformpoint

Let a plane follow the camera

So I have a feeling this is very simple, but can't get it right.

I want a horizon plane to follow the FPS style camera so the plane is always visible on the horizon. I came up with the following script. Problem is Vector forward also calculates directions. So when I look straight ahead, the horizon is at the desired distance. But, when I look up of down with the camera, the horizon comes towards the camera...

 horizonObject.transform.position = Camera.main.transform.TransformPoint(Vector3(0, 0, 70));
 
 horizonObject.transform.rotation = Quaternion.LookRotation(horizonObject.transform.position - Camera.main.transform.position);
 
 horizonObject.transform.position.y = 0;
 horizonObject.transform.rotation.x = 0;
 horizonObject.transform.rotation.z = 0;

Hope someone can help me...

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

Answer by DoctorMoney · Jul 28, 2014 at 04:47 AM

I'm not sure exactly what you're trying to do, but it sounds like parenting the plane to the camera would work. Just drag and drop it in the inspector and you should be fine. Disable this script when you try it though

Comment
Add comment · Show 2 · 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 Royall · Jul 28, 2014 at 01:32 PM 0
Share

Yes, but that will make the plane fly so it's always in view. But I want it to be at the horizon only at y=0;

avatar image Yofurioso · Jul 28, 2014 at 03:17 PM 0
Share

have you tried this?

     public float desiredDistance = 70f; //tweek this on inspector
     
     Vector3 horizonLocation = (camera.transform.position + camera.transform.forward * desiredDistance);
     
     horizonLocation.y = 0; //kills y coordinate so that the plane only moves sideways and back and forth
     
     horizonObject.position = horizonLocation; //Puts the horizon plane on the horizon
     horizonObjecto.rotation = Quaternion.LookRotation(horizonObject.transform.position - Camera.main.transform.position); //makes it look at the camera... migth as well use LookAt
     
     etc...

Hope it helps

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

How to freeze rotation of the camera 1 Answer

Following another object's position/rotation like parent/child relationship? 4 Answers

Using PositionHandle to set a a directional vector, using TransformDirection causing editor freakouts. Help! 0 Answers

rotate camera on mouse reaching edges 1 Answer

Rotate Object to face player 2d 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