0

my bird is colliding with the clouds but it only moves them and doesn't trigger it

my character

public float jumpForce = 5f;      
public float gravity = -9.81f;
public GameObject gus;
public Transform rotation_checker;
public Transform chekced;

float velocity;
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    gameObject.transform.eulerAngles = new Vector2(0,0);
    velocity += gravity * Time.deltaTime;
    if (Input.GetKeyDown(KeyCode.W))
    {
      velocity = jumpForce;
    }
    rotation_checker.position = chekced.position;
    transform.Translate(new Vector2(0, velocity) * Time.deltaTime);
   
 
}

private void OnTriggerExit2D(Collider2D collider) 
{
    Debug.Log(collider.gameObject);
    if(collider.gameObject.name == "skybluscene")
    {
        Destroy(gameObject);
    }
}
private void onCollisionEnter2D(Collision2D collision) 
{
    if (collision.gameObject.tag == "cloud")
    {
        Destroy(gameObject);
    }
}

the cloud

float x = -4f;
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    gameObject.transform.Translate(new Vector2(x, 0) * Time.deltaTime);

}


void OnTriggerExit2D(Collider2D collider) 
{
    if ( collider.gameObject.tag == "scene")
    {
      Destroy(gameObject);
    }
}

cloud works just fine, it destroys itself when it leaves the scene but bird doesn't destroy itself when it collides with the cloud

both bird and cloud have dynamic rigidbody2d and a collider

Kortay
  • 9
  • 1
  • First thing, I'm not sure if this is a typo mistake but your "OnCollisionEnter2D" method must be with capital "O". Second, if you can share a screenshot of your cloud collider and rigidbody2d that would be more helpful. – Pavlos Mavris Nov 12 '22 at 14:59

1 Answers1

0

First of all: On your character script, your onCollisionEnter2D is misspelled. It needs to start with a capital letter.

Second: all your other methods use tags to identify what GameObject they collided with, but "skybluscene" (which also looks like a typo) is identified by its gameObject name.

Third: I'm not sure, but I find it odd that you're using both triggers and collisions in the same script.

  • trigger is for if the object gets out of the scene and collision is for a collision with a cloud, thank you for helping me out – Kortay Nov 13 '22 at 14:10