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 hitting 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 this but either it ends up not colliding with anything or colliding with everything. 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 everything or collides with nothing. Please help.
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
@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 this 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);
}
}
}
Have you tried Destroy(other.gameObject)?