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 zTizzle · Nov 06, 2012 at 01:39 AM · raycastwall

Raycast not stopping at a wall?

Hi,

I'm making a slender game, and I have a raycast to see if the character is visible and take away from health if he is,

but my problem is that the raycast is not stopping at a wall. Here is the coding, I think whatever my error is it is in the function CheckIfVisible. Any help is appreciated! Thanks!

Comment
Add comment · Show 2
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 AlucardJay · Nov 06, 2012 at 01:49 AM 0
Share

What gets printed in the console when you un-comment the line :

 Debug.Log( "" + hit.collider.gameObject.name );
avatar image Myth · Nov 06, 2012 at 02:32 AM 0
Share

What are the collider settings on the slenderman? Do you have any layers that have different settings?

1 Reply

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

Answer by Seth-Bergman · Nov 06, 2012 at 04:26 AM

EDIT:

Deleted previous answer, it wasn't right anyway...

Since this script is known to work, and the issue at hand is that you are not detecting the walls, then, assuming the wall IS BETWEEN the two positions (enemy and player), this should work, so long as your wall has a COLLIDER.

IF your wall ALREADY has a collider, I guess just about the only other possibility is that one of your coordinates (thePlayer.position or theEnemy.position) is not what you expect..

to see for sure, use Debug.DrawLine

add this line at the top of the Update:

 Debug.DrawLine(theEnemy.position,thePlayer.position,Color.green);

and make sure your line is where you expect, and see if it passes through the COLLIDER of the wall

Comment
Add comment · Show 7 · 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 AlucardJay · Nov 06, 2012 at 04:55 AM 0
Share

I don't understand, I had no problem with using linecast when I wrote this. I just ran the project again, and uncommented the line

 //Debug.Log( "" + hit.collider.gameObject.name );

and the results were Terrain and Player, therefore if the collider name is Player then isVisible is true. For all other outcomes isVisible needs to be set to false before the script reaches the movement part.

That's why I left the line in there (for future people to uncomment and check the console).

I really am not sure why this isn't picking up your walls, all I can suggest is the basics which have already been suggested : do your walls have colliders, and are they layermasked/different layer to the raycast? And when you uncomment the Debug after the linecast, what is displayed in the console (just Player, or other objects come up)?

avatar image Seth-Bergman · Nov 06, 2012 at 05:31 AM 0
Share

seems like a linecast COULD work here.. but you wouldn't be checking for the PLAYER, as the line is BETWEEN the player and the enemy, and checking for occlusion between the two.. so you would ins$$anonymous$$d be checking for anything OTHER than those two objects, right?

in which case, I would use a layermask to avoid seeing either player or enemy,..

In other words, the PLAYER is one of the endpoints of the linecast, so checking for the hit to have the name "Player" makes no sense here

avatar image AlucardJay · Nov 06, 2012 at 05:51 AM 1
Share

To make it easy for writing a guide that was hopefully (but apparently not so) foolproof, I put the pick-up-paper script on the player, and everything else on the enemy (even the health system). Then I used name ins$$anonymous$$d of tag to make things easier too. I am not sure on your other points, from the enemy perspective : if the enemy is within the max visible range and is not occluded, then isVisible = true; For all other outcomes is false. The enemy is only interested in the player, so the only thing to be checking for is the Player, for all other conditions the enemy is either occluded to the player or too far away, and therefore isVisible = false;

As I said, the script is tested and working, while I only have player terrain and papers in the scene, the console debugs all these 3 objects, when the enemy is occluded to the player by these objects terrain or paper is printed, so the linecast works and returns the name of the gameObject it first collides with between player and enemy. I still fail to understand the issue when the script is tested and working. But it's all good, I continually learn from this 'site, suggestions thoughts and comments are welcome =] (but the script works!)

avatar image Seth-Bergman · Nov 06, 2012 at 06:21 AM 0
Share

O$$anonymous$$, my mistake then, guess I'm underthinking this :O

guess I see how this is working now, might have helped if I'd have known where this came from too :)

On second thought, you're surely right, the walls must not have colliders :D

avatar image AlucardJay · Nov 06, 2012 at 06:50 AM 0
Share

This is how the dot product and range zones are set up :

alt text

here is a package of the project :

http://www.alucardj.net16.net/unityanswers/SlenderGuideV1-scene0.unitypackage

create a new project, then import the above asset. Open the folder _Scenes and then open scene0. Use the E key in the editor to pick up papers so that ScreenLock doesn't break, but hopefully adding the edits to the pick-up-paper script will make it work if ScreenLock breaks =]

Show more comments

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

14 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

Related Questions

Detect if GameObject is Touching an Imported Level 0 Answers

how to use raycasting for enemy sight (C#)? 3 Answers

Wall running using raycasting. 2 Answers

Going through wall 2 Answers

Detecting collisions with raycast or not? 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