Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Badgerfish · Sep 25, 2015 at 04:27 PM · raycastline of sight

Line of Sight and Raycasting

I'm working on a small tabletop strategy game port. For it to work properly a couple of things are afforded as liberties:
1. The 'units' are cylinders, so line of sight to and from them can be taken from any point in the cylinder.
2. The accuracy is irrelevant, since it will be calculated with a percentage or roll based on the unit's stats.

My current problem is raycasting, I'm testing to see if I can use it as a method for determining Line of Sight, but my current code is behaving oddly, so I can't test it properly. I might be missing something basic.
My problems are:
1. Raycasting from one unit to another always turns up as failing (false), but when I test the raycast against a basic object like a cube, sphere, or even a plain cylinder, it works mostly fine. alt text alt text 2. When I raycast through terrain, the ray registers a hit, and ignores the terrain completely. (same as image 2, but through a wall)


Is this the best way of doing line-of-sight tracking for this type of game or do I have other choices?

Is something wrong with this code?`if (Input.GetKey (KeyCode.F)) {

         RaycastHit hit;

         if(Physics.Raycast(transform.position, transform.position - target.transform.position, out hit, 100)){

             Debug.Log("Hit:" + hit.transform.gameObject.tag);
             Debug.DrawRay(transform.position, (target.transform.position - transform.position) * 100, Color.green);
             Debug.Log(hit);
         }else{
             Debug.DrawRay(transform.position, (target.transform.position - transform.position) * 100, Color.red);
         }
     }`


shoot.png (190.9 kB)
shoot2.png (173.7 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

28 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 avatar image avatar image avatar image avatar image 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

Best way to calculate damage of explosions 1 Answer

Line of sight for multiple targets - AI - in a 2d game 1 Answer

checking line of sight with raycasts (2D) 1 Answer

Edge collider BoxCast issue 0 Answers

OnPointerEnter blocked by something 2 Answers


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