Search Unity

Trigger is not executed

Discussion in 'Physics' started by frankfringe, Feb 24, 2019.

  1. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    105
    Hi,

    I have one 2D Object
    Rocket
    with a Rigidbody2D and a Capsule Collider 2D which is set to isTrigger.
    I have another empty game object
    Border
    which has a line collider attached.
    The code for
    A
    is:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Rocket : MonoBehaviour
    6. {
    7.     public Rigidbody2D rb;
    8.     public float thrust = 300f;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody2D>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.     }
    19.  
    20.     void OnMouseDown()
    21.     {
    22.         //rb.AddForce(transform.forward * thrust);
    23.         rb.AddForce(transform.up*thrust);
    24.     }
    25.  
    26.     private void OnTriggerEnter(Collider other)
    27.     {
    28.         print("Collided, rotating");
    29.         transform.Rotate(Vector3.forward * (360 - transform.rotation.eulerAngles.z));
    30.     }
    31.  
    32. }
    33.  
    OnTriggerEnter
    is never called, even when they obviously do collide (I made sure that
    Rocket
    moves slow enough s.t. they do collide). As soon as I deactivate the
    isTrigger
    property on
    Rocket
    , they collide and the the collision is resolved by the physics system. I checked the collision matrix, everything there is set to true. I also tried adding a kinematic Rigidbody to
    Border
    which did not help.

    Does anyone know what could cause this?
    Thanks
     
  2. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    105
    I now also tried to set both as
    isTrigger
    with no luck
     
  3. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    105
    I used the 3D methods instead of the 2D methods which of course did not get triggered...