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 Edyvargas · Nov 03, 2011 at 05:01 AM · triggerbullet

Bullets collide with a Trigger

Hi, i have a door with a trigger that activate animations only when the object tag "Player" collides with it, the problem its that my bullets for some reason collides with the trigger too, i dont know if the problem are on the bullets or on the door code.

this is part of the door code:

     function OnTriggerEnter(hit:Collider){
 
     if(hit.gameObject.tag == "Player"){
     
         action = true;
     }
 }
 
 function OnTriggerStay(hit:Collider){
 
     if(hit.gameObject.tag == "Player"){
     
         trigger = true;
     }
 }

The bullets are prefabs with box collider and rigidbody on it, and the shoot proyectile script is this (i get it from a tutorial):

 var shotsound:AudioClip;
 var shellPrefab : GameObject;
 var proyectilevelocity:int;
 var ammo:int;
 var fireRate = 1.0;
 private var nextfire = 0.0;
 function FixedUpdate () {
     if(Input.GetButton("Fire1") && Time.time>nextfire && ammo>0)
         ShotProyectile();
 }
 function ShotProyectile(){
         if(Time.time > nextfire)
         {
     var Grenade:GameObject = Instantiate(shellPrefab,transform.position,transform.rotation);
     Grenade.GetComponentInChildren(Rigidbody).velocity =transform.TransformDirection(Vector3(0,0,proyectilevelocity));
     //Physics.IgnoreCollision(shellPrefab.GetComponentInChildren(BoxCollider).collider,transform.parent.collider);
     ammo--;
     if(shotsound)
         audio.PlayOneShot(shotsound);
     Destroy(Grenade,10);
     nextfire = Time.time+fireRate;}
 }

Thanks for any help or idea.

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

2 Replies

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

Answer by Edyvargas · Nov 03, 2011 at 09:01 AM

UPDATE:

I found the problem!, was the DontGoThroughThings.js script, used to shoot fisic bullets at fast speeds and make collision always using a raycast on the bullet object itself (very useful script to solve the missed collisions problem on fast movement objects).

Without this script attached to the bullet, the shooting through triggers behavior is normal, just the problem of some missed collisions if the bullet goes too fast, if someone have an idea on how to solve this on the mentioned script, you can see it on the upper link, thanks for the help.

Comment
Add comment · Show 4 · 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 syclamoth · Nov 03, 2011 at 09:08 AM 0
Share

Oh, that thing! Yeah, it uses raycasts to manage its inbetween bits, so my solution about the raycasts should fix it. Or, just make sure that the layermask on it doesn't include the layer that your triggers are on.

You should have mentioned that you were using that script! It explains everything.

avatar image Edyvargas · Nov 03, 2011 at 09:12 AM 0
Share

Yes, i forgot that detail :)...., the layermask excluding the door (the part with the trigger) layer works O$$anonymous$$, and keeping the other door parts on the default layer, but the collisions with the other parts of the door, sometimes makes a funny bullet behavior, like if the bullets where floating when collides...but just sometimes...

avatar image syclamoth · Nov 03, 2011 at 09:14 AM 0
Share

Basically, if you follow the tips in my answer, it automatically fixes the problems with DontGoThroughThings, and keeps all of its advantages. So go do that. $$anonymous$$ostly, the 'Raycasts Hit Triggers' bit should fix it.

avatar image Edyvargas · Nov 03, 2011 at 10:20 AM 0
Share

You are right, thanks, disable the "Raycasts Hit Triggers" solve the problem at all, and i found that the funny floating bullets, appears on some collisions, even without the DontGoThroughThings script...but only with capsule type bullets, with cube bullets all works like a charm..., interesting...

UPDATE: If i let the "Raycasts Hit Triggers" on, and use a specific layer for all the triggers, and then add this layer to the layermask and avoid collisions to it, has a strange effect on the cube type bullets too, and make them floating a bit sometimes when hits on a collider.

avatar image
1

Answer by syclamoth · Nov 03, 2011 at 05:40 AM

There are a few ways of fixing this. The simplest one is to just go to your Physics settings, and disable 'Raycasts Hit Triggers'. If that's not an option (because it'll stop other things from working properly), you can put all your triggers on a "triggersOnly" layer, and then use a layermask on your bullet raycasts to stop them from colliding with your triggers.

EDIT: Oh wait, you're using rigidbodys for your projectiles? In which case I can't really explain why they're colliding with the trigger. Triggers should never interact with rigidbodies, other than to send messages, and you're already checking for player tags in your OnCollision bits. Otherwise, go to your Physics settings (again) and set up the collisions matrix so that projectiles never collide with trigger volumes (somehow).

Comment
Add comment · Show 1 · 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 Edyvargas · Nov 03, 2011 at 06:14 AM 0
Share

Hi, thanks for the help, you are right, i dont know either why the bullet prefabs (with rigidbody) are colliding with triggers, but i will find out somehow, i think there is nothing to do with the door script, beacuse the same happens with other triggers.....

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

On TriggerEnter issues 1 Answer

Bullet Penetration not working 1 Answer

An integer that's supposed to get incremented gets reset when a bullet hits. 0 Answers

Why do my bullets only destroy themselves sometimes after colliding with the wall? 0 Answers

Can't click gameobject when over another trigger? 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