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 Infinite_Gamer · Apr 16, 2014 at 03:27 AM · c#playerraycasthitparkour

Raycast does not detect Objects

Hello unity community.

to cut to the chase what I am doing is I am trying to make a parkour system and what it needs to do is detect if a wall it "X" amount away from the player. I have a raycast to check if the player is grounded and that works perfectly. That is why I think I dont know what is wrong.... So the problem that is happening is that I have a raycast shooting to the right of the player and this raycast does not detect gameobjects. Please any help is welcomed.

here is my parkour script

 //public
     public GameObject RaycastShooter;
     public float ParkourIfLessThan = 1f;
     public float WallRunSpeed = 9.75f;
 
     //Distances
     public float WallDistance = 1f;
 
     //Bools
     private bool CanWallRun;
     private bool IsWallRunning;
 
     //Raycast
     private Vector3 RightRay = new Vector3 (1,0,0);
 
     // Use this for initialization
     void Start () 
     {
         
     }
     
     // Update is called once per frame
     void Update () 
     {
         //All the different Raycast hit
         RaycastHit RightHit;
         RaycastHit LeftHit;
         
         if(Physics.Raycast(RaycastShooter.transform.position, RightRay.normalized, out RightHit, WallDistance))
         {
             float DistanceToWall = RightHit.distance;
             if(DistanceToWall <=  ParkourIfLessThan)
             {
                 print("can wall run");
             }
             if(DistanceToWall >  ParkourIfLessThan)
             {
                 print("Can't wall run");
             }
             Debug.DrawLine(RaycastShooter.transform.position, RightHit.point);
         }
 
     }
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 Infinite_Gamer · Apr 16, 2014 at 11:50 AM 0
Share

Ok thank you I will try this once I get to my pc

avatar image Infinite_Gamer · Apr 16, 2014 at 08:31 PM 0
Share

Just tested this on my PC and it works great :D thank you for your help.

2 Replies

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

Answer by robertbu · Apr 16, 2014 at 03:30 AM

Note that RightRay is the world right. For most 3D games, you want to raycast from the right of the object. Something like:

    if(Physics.Raycast(RaycastShooter.transform.position, RaycastShooter.transform.right, out RightHit, WallDistance))

Since I don't know your game mechanic, I'm not sure this is your problem. Also you might want to do a Debug.DrawRay() with exactly the same parameters as your Raycast() so you can visualize any Raycast().

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

Answer by drudiverse · Dec 05, 2015 at 09:41 AM

Check the distance of the raycast. i.e. 100 meters may only capture half the objects, prblem i had, in physics.raycast() function

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

21 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

Related Questions

Multiple Cars not working 1 Answer

How to undo destroying a component, after 5 seconds. 0 Answers

Finding the player that walked into a ray? 1 Answer

Follow Camera Interferes with Player Movement? 0 Answers

Third person movement similar to Max Payne 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