Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Jul 27, 2015 at 03:37 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by JoeIkin · Jul 20, 2015 at 04:01 PM · cameraraycastcamera movement

Raycast only works in cartain areas of scene

I am building an RTS style city building game and am havig an issue which I believe is connected to raycasts and the camera. I am using raycasts to determine where on the ground buildings are to be placed, however I cannot place buildings in certain areas towards the top and bottom of my map and I am unsure why. I am using an orthographic camera and if I change the position, or clipping planes of the camers the areas where I am unable to place buildings also changes.

Any help would be appreciated, thanks in advance.

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

  • Sort: 
avatar image
0
Best Answer

Answer by Geva93 · Jul 20, 2015 at 10:42 PM

I think its because you dont use layers, check if the camera ray cast is on the all layers.

Comment
Add comment · Show 6 · 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 JoeIkin · Jul 27, 2015 at 09:39 AM 0
Share

I am using this code to only check layer 10, which is the "terrain" layer. I may be using it incorrectly, I am new to raycasts.

RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 400, 1 << 10)) { p = hit.point; }

avatar image meat5000 ♦ · Jul 27, 2015 at 10:27 AM 0
Share

Define the layer in advance as a type Layer$$anonymous$$ask

 Layer$$anonymous$$ask myLm = 1 << 10;

I do believe if you dont do this 1 << 10 could register as an int which is not what it wants.

avatar image JoeIkin · Jul 27, 2015 at 11:20 AM 0
Share

I believe that I am telling the ray cast to only apply to the "terrain" layer, which is layer 10 using this code

RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 400, 1 << 10)) { p = hit.point; }

avatar image AlwaysSunny · Jul 27, 2015 at 11:21 AM 0
Share

@$$anonymous$$kin Please post non-answers as comments and format code with 101010 button, thanks,

avatar image JoeIkin · Jul 27, 2015 at 01:17 PM 0
Share

thanks I have made this change now, and can now place buildings correctly anywhere on half of my map, however if I pan to the right and attempt to place objects on the other half then the buildings stop following the mouse until I bring the cursor back onto the first half of the scene. All terrain objects are placed in the correct layer, could this be an issue with how I am moving my camera?

Show more comments

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Smooth camera on moving platform 1 Answer

Unity Android Movement Problem 0 Answers

How to move a camera only using the arrow keys? 7 Answers

Detect Mouse in right side or left side For Player? 2 Answers

Camera to aim at raycast 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