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 Nov 19, 2016 at 09:10 PM by SgtShadowWalker.
avatar image
0
Question by SgtShadowWalker · May 27, 2015 at 10:50 AM · cameraraycastcolliderraycastinggun

Raycast hits player when looking down

Hi,

I made a few weapons in my game that use raycasting, blah blah, particles and a bulletshole spawn where the raycast hits. But there's a problem that I can't seem to fix.

As you can see in the video linked below, every time I shoot down, a bullet hole appears where my camera is. (https://youtu.be/sUVtZm__afU) I've checked everything and made sure there were no colliders blocking the way, but it's still hitting the camera every time I look down.

Does anyone know what might be causing this?

Thanks

Comment
Add comment · Show 4
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 gabrielcac · May 27, 2015 at 11:35 AM 0
Share

Try adding a debug call to print the name of the object hitted by the ray cast, so you know who is on the way. Assu$$anonymous$$g there is nothing on the way of your raycast, could it be that your script is adding a bullet hole even when the raycast doesn't hit anything?

avatar image gabrielcac · May 27, 2015 at 12:08 PM 0
Share

Try adding something like this after your if statement:

 if(hit != null)
 {
     Debug.log("Raycast hitted " + hit.collider.gameObject.name);
 }
avatar image SgtShadowWalker · May 27, 2015 at 12:12 PM 0
Share

It said it was hitting the play collider that I want to use for hit detection, so I'm going to have to find a way around that. But even when I disabled that collider, it would still do the same thing, except that it would now hit the ground, which is what I'm standing on. I really have no idea why it would put a bullet hole in the air if it's hitting the ground.

avatar image SgtShadowWalker · May 27, 2015 at 12:18 PM 1
Share

Thank you, that sounds like it might just work! I'll try it out soon

1 Reply

  • Sort: 
avatar image
0

Answer by virgiliu · May 27, 2015 at 12:15 PM

Use a layer mask in the Raycast() so the ray only collides with a certain layer http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

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

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I check for collisions when I move objects based on Time.deltaTime? 3 Answers

Raycast Collider Tag not returning correct result 1 Answer

raycast not colliding 1 Answer

Logic to detect objects entering between the player and camera? 1 Answer

Raycast not hitting collider 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