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 popcornistleckerokay · Jul 01, 2020 at 08:56 PM · scripting problemraycastcolliderbugshooting

Why do I sometimes hit my Collider and sometimes not

Hello,

I've made a shooting system where you shoot a projectile and on this projectile is a raycast attached and as soon as the raycast hits a collider, the collider and the projectile gets destroyed.

So far so good and in fact it works in 80% of the cases but SOMETIMES the projectile just flying CLEARLY through the collider without doing anything.

I have literally no idea how to deal with the problem and for me this looks like a bug.

It would be great if anyone have an idea or even better a solution for the problem.

If needed i can post the script or images.

Thanks for help in advance :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LeFlop2001 · Jul 01, 2020 at 09:06 PM

Why are you both using projectiles and raycasts, in the fps genre it is common to use either use raycast (simplified and less performence heavy) or a projectile (realistic), if youre using a projectile you could simply use the OnCollisionEnter() method. Regarding your problem there are a number of things that could cause this probleme and you would have to share some code to get a satisfying answer. But again i would not recommend your approach.

Comment
Add comment · Show 3 · 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 popcornistleckerokay · Jul 01, 2020 at 09:12 PM 0
Share

hello, in fact im using raycast cause of the reasons you mentioned and they recognize the gameobject and in most cases it works properly but sometimes the bullets just fly through the gameobject even tho the raycast hit the gameobject

avatar image popcornistleckerokay · Jul 01, 2020 at 09:20 PM 0
Share

Heres the code:

     void Update()
     {
         countdown -= Time.deltaTime;
         RaycastHit hit;
        
        Ray landingRay = new Ray(this.transform.position, this.transform.forward);
 
         if (Physics.Raycast(landingRay, out hit, dephei,layer$$anonymous$$ask))
         {
            
             Debug.Log(hit.collider.gameObject.name);
 
           
 
 
 
             Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, radius);
             
             foreach (Collider nearbyObject in collidersToDestroy)
             {
                 EnemyStats target = nearbyObject.transform.GetComponent<EnemyStats>(); //getcomponent<Target> um auf eine funktion im anderen skript zuzugreifen
                 Rigidbody rb = nearbyObject.GetComponent<Rigidbody>();
                 if (rb != null)
                 {
                     rb.AddExplosionForce(force, transform.position, radius);
                 }
 
                 Destruct dest = nearbyObject.GetComponent<Destruct>();
                 if (dest != null)
                 {
                     GameObject impactGO1 = Instantiate(pickupEffect, transform.position, transform.rotation);
                     Destroy(impactGO1, 2f);
                     Destroy(gameObject);
                     dest.Destroy();
 
                 }
 
                 if(target != null)
                 {
                     GameObject impactGO2 = Instantiate(pickupEffect, transform.position, transform.rotation);
                     Destroy(impactGO2, 2f);
                     Destroy(gameObject);
                     target.TakeDamage(damage);
 
                 }
 
             }
 
             Destroy(gameObject);
 
 
 
            GameObject impactGO =  Instantiate(pickupEffect, transform.position, transform.rotation);
             Destroy(impactGO, 2f);
 }
avatar image LeFlop2001 popcornistleckerokay · Jul 02, 2020 at 06:13 AM 0
Share

i cant tell from the script you provied how fast your projectile is supposed to be traveling but if the distance it travels every frame is greater than the width of the object youre trying to hit there is a chance it will just telereport right through it and raycast wont change that(unless you give them a big enough range), but the rigidbody has a dropdown window labeled collision detection where you can choose between discrete (which is the most performent option) and a selection of continuous options. Continuous means that its checks the traveled collision ins$$anonymous$$d of just the position for collision wich should fix your issue. if you choose to stick with your raycast id try a bigger range

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

306 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 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 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 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 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 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 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 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 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 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 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

My Raycast Won't Fire 1 Answer

scripting problem 0 Answers

Does RayCast crosses mesh colliders? 2 Answers

How to get bullets to hit crosshair 2 Answers

Finding a certain variable is failing 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