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 naveenrai8 · Apr 11, 2013 at 09:52 AM · cameracamera-movement

Always Place an object in front of camera

Hi All,

I need to find at run-time at which direction camera is looking at. So I thought to to place an object always in front of camera, irrespective of where the camera is currently looking at. E.g. If camera faces towards +x axis, then object should be placed in front of camera along the x axis.

I tried create a cube, make it child of camera and place it at some distance d in front of camera, but as camera moves, child object doesnt move.

I have searched a lot but could not find anything related. I am not planning to attach any Rigidbody component with the object.

Please someone help me out!

If this is a duplicate question then please point me to the thread but please please dont close this thread as I need to solve it urgently.

Thanks in advance!!!!

Comment
Add comment · Show 5
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 whydoidoit · Apr 11, 2013 at 09:53 AM 0
Share

The child object will move if its parented to the camera and the camera is moving.

What do you want to do with this direction? Camera.main.transform.forward is the direction that the current main camera is looking in.

avatar image naveenrai8 · Apr 11, 2013 at 10:36 AM 0
Share

Hi whydoidoit, does Camera.main.transform.forward always point to the forward of camera or it points to wherever +ve z axis is? I means, if my camera facing -ve y-axis, would Camera.main.transform.forward points to -ve y-axis or +ve z axis?

avatar image whydoidoit · Apr 11, 2013 at 10:36 AM 0
Share

Please post comments using the "add new comment" button - on UA Answer means Solution and not Reply. I've converted it for you this time.

avatar image whydoidoit · Apr 11, 2013 at 10:37 AM 0
Share

It is always the direction of the camera - the camera's local Z axis represented as a world space direction.

avatar image naveenrai8 · Apr 11, 2013 at 11:04 AM 0
Share

Thanks a lot whydoidoit :) u rock!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by HmoudMO · Apr 11, 2013 at 10:18 AM

You can either add the object as a child of the object, or you can have a script as follows:

 void Update()
 {
    transform = Camera.main.transform;
    transform.position.z = Camera.main.transform +5 ;
 }
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 whydoidoit · Apr 11, 2013 at 10:18 AM 0
Share

Not sure what you are on about with that script - but it's totally wrong.

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

12 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

Related Questions

Free Look Camera 1 Answer

Camera Follow works partially, need help to finish the script 3 Answers

How can I mimic this game's camera in Unity? 1 Answer

Having camera point and shift around origin? 1 Answer

2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 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