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 /
This question was closed Oct 22, 2013 at 05:33 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Tanshaydar · Oct 20, 2013 at 09:46 PM · raycastcharacter controller

Raycast Doesn't Hit Character Controller

Hi,

I have an enemy with line and angle of sight. However when I check if it can directly see the player, Raycast never hits the player. To check if it works, I put some other game objects like cubes, and Raycast reports them.

Example:

alt text

As you can see, Debug.DrawRay goes through player but RayCast info only gives Plane as the info.

This is the code I am using.

         Vector3 direction = other.transform.position - transform.position;
         float angle = Vector3.Angle( direction, transform.forward);
         
         if( angle < fieldOfViewAngle * 0.5f){
             
             RaycastHit hit;
             
             if( Physics.Raycast( transform.position + transform.up, direction.normalized, out hit, col.radius)){
             
                 Debug.Log("Name: " + hit.collider.gameObject.name + " Tag: " + hit.collider.gameObject.tag);
                 //if( hit.collider.gameObject == player){
                 
                 if( hit.collider.gameObject.tag == "Player"){
                 
                     playerInSight = true;
                     Debug.Log("Enemy sees Player");
                     lastPlayerSighting.position = player.transform.position;
                     //personalLastSighting = player.transform.position;
                     
                 }
             }
         }



Comment
Add comment · Show 20
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 bpears · Oct 20, 2013 at 10:02 PM 1
Share

you havent defined col.radius

avatar image bpears · Oct 20, 2013 at 10:05 PM 1
Share

So you're trying to cast a distance of 15. Just set distance to $$anonymous$$athf.Infinity, why do you want o use the colliders radius?

avatar image Miziziziz · Oct 20, 2013 at 10:08 PM 1
Share

did you put the player under the "Ignore Raycast" layer?

avatar image bpears · Oct 20, 2013 at 10:10 PM 1
Share

sounds silly but, did you forget to tag as "Player" in inspector

avatar image bpears · Oct 20, 2013 at 10:14 PM 1
Share

make sure your tagging the object with the collider and not a child or parent of it that has no collider.

Show more comments

1 Reply

  • Sort: 
avatar image
4
Best Answer

Answer by Tanshaydar · Oct 21, 2013 at 11:26 PM

For anyone out there wondering if there is a solution... Raycasting never detects the Character Controller. It is a special type of collider and it doesn't play well with other components.

I solved my issue through replacing my FPS Controller with Rigidbody FPSWalker. You can find it in here: http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker

My code and game works now. Thanks everyone who tried to help.

Comment
Add comment · Show 12 · 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 sdgd · Oct 21, 2013 at 10:05 PM 1
Share

your question solved my problem :)

no raycast doen't hit anything else than normal collider

Raycast doesn't hit even collider trigger means I've got bigger problems than before but, ... now you know what doesn't work.

avatar image bpears sdgd · Oct 21, 2013 at 10:23 PM 0
Share

yes, you must have a collider. I imagined they had one since they were trying to return hit.collider info. Never assume I suppose...

avatar image whydoidoit sdgd · Oct 21, 2013 at 10:58 PM 0
Share

A CharacterController is a collider...

avatar image sdgd sdgd · Oct 21, 2013 at 11:10 PM 1
Share

yes but not for raycast, ...

avatar image Miziziziz · Oct 22, 2013 at 05:17 PM 1
Share

would using Collider.Raycast work? ins$$anonymous$$d of Physics.Raycast

avatar image Tanshaydar · Oct 22, 2013 at 05:42 PM 0
Share

Casts a Ray that ignores all Colliders except this one. So, it is looking for a collider again. Not gonna work on character controller either, but you are welcome to try.

avatar image Miziziziz · Oct 22, 2013 at 07:20 PM 1
Share

what about adding another collider(on an empty gameobject) as a child to the fps controller?

avatar image Tanshaydar · Oct 22, 2013 at 07:22 PM 0
Share

I don't think that's a good idea to go about.

Show more comments

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Gun script using Physics.Raycast not working? 2 Answers

Continuously rotate a gameobject on 1 axis perpendicularly to another gameobject's normal? 1 Answer

Creating custom character controller collision checking 0 Answers

How to add platform motion to player controller without parenting? - Mostly working code 1 Answer

Infamous first light run system, problem with my code, HELP 0 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