• 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
Question by Flaymes · Jul 07, 2020 at 05:29 PM · 2d collision

2D COLLISION NOT WORKING WITH TAGS

I am making a 2D game much like Doodle Jump. A bird AI follows the character and changes scene on collision. Although, I do not want the bird changing scene when $$anonymous$$tting the platfroms so I want a script that changes scene when colliding with a gameobject with the tag Player. I have tried many different ways to do t$$anonymous$$s but either it ends up not colliding with anyt$$anonymous$$ng or colliding with everyt$$anonymous$$ng. Please Help!,I am making a 2d game much liked doodle jump but there is a bird ai following the character. I dont want the bird colliding with the platforms though but I am unsure how to make it so the bird only kills me if it collides with a gameobject with the tag Player. I have tried many different ways but either the bird collides with everyt$$anonymous$$ng or collides with not$$anonymous$$ng. Please help.

Comment

People who like this

0 Show 0
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

3 Replies

· Add your reply
  • Sort: 
avatar image

Answer by YURI_uwu · Jul 07, 2020 at 07:21 PM

Hmm have you tried adding a Rigidbody2D component to the bird or the player? Can I at least see your code so I can determine where the problem is

Comment

People who like this

0 Show 2 · 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 Flaymes · Jul 08, 2020 at 04:33 PM 0
Share

Ok i will share the code with you

avatar image Flaymes · Jul 08, 2020 at 04:45 PM 0
Share

@MATEOICHIJO I just responded to you with the code and some information in the answer below

avatar image

Answer by Flaymes · Jul 08, 2020 at 04:43 PM

@MATEOICHIJO The bird and the player both have box collider 2d and rigidbody 2d, the bird is a trigger, here is the brid ai code =

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

[RequireComponent(typeof(Rigidbody2D))] public class EnemyAI : MonoBehaviour {

 public Transform target;

 public float speed = 5f;
 public float rotateSpeed = 200f;

 private Rigidbody2D rb;

 // Use t$$anonymous$$s for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody2D>();
 }

 void FixedUpdate()
 {
     Vector2 direction = (Vector2)target.position - rb.position;

     direction.Normalize();

     float rotateAmount = Vector3.Cross(direction, transform.up).z;

     rb.angularVelocity = -rotateAmount * rotateSpeed;

     rb.velocity = transform.up * speed;
 }


 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         Destroy(col.gameObject);
     }
 }

}

Comment

People who like this

0 Show 0 · 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

Answer by Cubemann · Apr 04, 2021 at 10:48 PM

Have you tried Destroy(other.gameObject)?

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

132 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

Related Questions

Is the 2D physics collision matrix different? 2 Answers

OnTrigger and Input.getkey on picking up weapons from the ground. 2 Answers

How can I make a "mobile" boundary? 0 Answers

How to destroy two gameobjects when they collide? 3 Answers

OnCollisionStay2D is ignoring collisions 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