• 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
1
Question by Nikke · Feb 07, 2011 at 02:37 PM · cameravectorlook

How to get the look (or forward) vector of the camera?

Hi,

I need to raytrace a line from the camera until the point on the ground the user is looking at. For this I need the look vector of the camera, any idea how I can get it?

Thanks, Nick

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

3 Replies

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

Answer by PrimeDerektive · Feb 07, 2011 at 02:54 PM

Should be the same as any other GameObject, transform.forward.

Unity camera's frustrums always point in the same direction as their transform's forward vector (transform.forward).

So if you do Physics.Raycast(transform.position, transform.forward, hit, length) it will shoot a ray towards whatever is directly in the center of the camera's frustrum.

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 e.bonneville · Feb 07, 2011 at 02:56 PM 2
Share

How have I not heard of that until now?! Well, I guess you learn something new every day. :)

avatar image Nikke · Feb 07, 2011 at 03:24 PM 0
Share

Thank you, that did the trick!

avatar image
1

Answer by e.bonneville · Feb 07, 2011 at 02:54 PM

Use transform.InverseTransformDirection.

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 Jesse Anders · Feb 08, 2011 at 02:03 AM 0
Share

InverseTransformDirection() isn't relevant to the problem (at least not as stated).

avatar image
0

Answer by LarryTheBrave · Mar 23, 2019 at 10:33 PM

Forward in Unity or "Which way this object is considered pointing?" would be along the local Z axis. Parent the object to the camera and have everything 0 except add something to Z. Then it will appear "in front of" the parent object at all times.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Why does my Mathf.SmoothDamp work for the Camera? 0 Answers

Unity Android Movement Problem 0 Answers

Want to apply "height" to my DeadSpace Camera --> Physics.Linecast gives me trouble 1 Answer

Sample the height of the mesh? 1 Answer

GUI Window on GameObject location? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges