- Home /
Trigger is not executed
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:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket : MonoBehaviour
{
public Rigidbody2D rb;
public float thrust = 300f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
//rb.AddForce(transform.forward * thrust);
rb.AddForce(transform.up*thrust);
}
private void OnTriggerEnter(Collider other)
{
print("Collided, rotating");
transform.Rotate(Vector3.forward * (360 - transform.rotation.eulerAngles.z));
}
}
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
Answer by xxmariofer · Feb 25, 2019 at 08:01 PM
Hello, you are mixing 2d with 3d. the event is OnTriggerEnter2D
Your answer
Follow this Question
Related Questions
Inexact rebound when colliding into corner of two walls. 0 Answers
Why do two colliders cross at high force? 0 Answers
What exactly is RelativeVelocity? 1 Answer
Object bounces without colliding 1 Answer
Slow down object about to collide 1 Answer