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
1
Question by omarrob · Jun 28, 2012 at 11:10 AM · enemybulletturretignorecollision

making an enemy bullet ignore other enemies

so i have a 2d game where i have a turret coming out of the wall and shoots non-stop and a robot walking in its range, i'm not very experienced but i looked for an answer of how to make the enemy bullets ignore the robot, i found physics.ignorecollision but i had no luck trying it, what is happening now is that the bullets are throwing the enemy away any help would be appreciated and here are my scripts

this one is for the machine gun(turret)

public GameObject bullet; public Transform obj; // Use this for initialization void Start () {

 }
 
 // Update is called once per frame
 void Update () {
 GameObject KEBUMZ;
     KEBUMZ= Instantiate (bullet, obj.position,obj.rotation ) as GameObject;
     KEBUMZ.rigidbody.AddForce(obj.forward*2000);
     
     
 }

}

and this one is for the bullet

public class Bullet : MonoBehaviour { public GameObject Wobot;

 void start(){
      Physics.IgnoreCollision(Wobot.collider, collider);
 }
 // Update is called once per frame
 void OnTriggerEnter (Collider Missle) {
     
 if(Missle.tag !="enemy"  ){
         
     Destroy(gameObject);
 }

} }

Thank you.

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
2
Best Answer

Answer by aldonaletto · Jun 28, 2012 at 12:29 PM

There are some alternatives:
1- Use layers: create a new layer (Enemies, for instance - button Layers, option Edit Layers) and select this layer in the enemy and bullet prefabs (field Layer, in the Inspector), then uncheck the crossing of Enemies x Enemies layers in the Physics Manager (menu Edit/Project Settings/Physics) - this will make enemy bullets pass through the enemies without any collision, while preserving collisions with anything else that isn't in the Enemies layer.
2- Use mass ratio: set the bullet mass to a small value - like 0.01, for instance - this will reduce the bullet impact (99%, if 0.01 is used). The bullets will still be destroyed when hitting enemies, but the impact will not be noticeable.

No matter which's the preferred alternative, you should use OnCollisionEnter to detect rigidbody collisions - OnTriggerEnter only works for triggers. Making the bullet's collider a trigger could be a 3rd alternative, with effects similar to the second one: the bullets will be destroyed when hitting anything, but there will not exist any impact.
If the bullet has a normal collider (Is Trigger unchecked), your collision code would become something like this:

...
void OnCollisionEnter (Collision Missle) {
  if (Missle.transform.tag !="enemy"){
    // apply damage to the object hit 
  }
  Destroy(gameObject);
}
The way you apply damage usually is by SendMessage or by direct call to some player's damage function:

// using SendMessage - this code calls the function ApplyDamage(5) in any hit object, // if such function exists: Missle.transform.SendMessage("ApplyDamage", 5, SendMessageOptions.DontRequireReceiver);

// using direct calls - this code calls the function ApplyDamage(5) in the HealthScript // script, if this script is attached to the hit object: HealthScript hScript = Missle.transform.GetComponent< HealthScript>(); if (hScript) hScript.ApplyDamage(5);

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 omarrob · Jun 28, 2012 at 12:36 PM 0
Share

once again, you saved me :) thank you.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Turret bullet rotation problem 1 Answer

No collision on trigger and character controller 1 Answer

Radial/omni directional shooting Problem 1 Answer

On TriggerEnter issues 1 Answer

Turret won't shoot 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