Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 troneras · Mar 20, 2012 at 10:45 PM · raycastraycastingraycasthit

Is this way of making a raycast correct

Hi, I was having problems for checking if there was an object between the cámera and my player. I finally used this:

ray = camera.ScreenPointToRay(camera.WorldToScreenPoint (tr.position));

Is that correct?

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

2 Replies

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

Answer by DaveA · Mar 20, 2012 at 10:47 PM

Depends on what you mean by 'camera'. If you mean 'in view of the camera' then do you mean from the center of the view? If you mean the object holding the camera, then you can construct a Ray between that object's transform and the player and see if it hits anything before the player.

But in short, if it works, hey, ok.

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 troneras · Mar 21, 2012 at 12:02 AM 0
Share

Thanks. Yes, I refeer to the first, I have the camera following the player and always looking to the player position. Because the player it's always at the center I tryed to pass Vector3(0.5,0.5,1.0) but it doesn't work. I think in my case that would be the best solution(if it worked).

avatar image troneras · Mar 21, 2012 at 09:37 AM 0
Share

lol..Ok I was thinking in other thing, the Screen goes from 0 to Screen.height and from 0 to Screen.width. Not from 0 to 1...

avatar image
0

Answer by troneras · Mar 21, 2012 at 12:07 AM

I found a better solution: In function Start() I keep the position of the sphere relative to the screen, it's center!:

midX = Screen.width/2; midY = Screen.height/2; screenPos = Vector3(midX,midY,1);

This way I have one less transform per update.

ray = camera.ScreenPointToRay(screenPos);

Since I always have my camera looking to the sphere, this works great.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Raycast Not Drawing In Target Direction 0 Answers

Help with Raycast C# 0 Answers

Raycast exit point of collider 0 Answers

Problems with 2D RaycastHit.Collider 2 Answers

raycastHit.point - How do I make it ignore colliders? 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