Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
How can I prevent non-trigger colliders from pushing each other in Unity?

I got pre-made projectiles from the Unity's asset store and couldn't figure out a way to make them work my intended way.

The projectiles have colliders (not triggers), rigidbody and a script that moves them by .velocity. It detects a collision using OnCollisionEnter, making them push objects that have rigidbodies (behavior not wanted).

I could indeed use OnTriggerEnter, but the projectile spawns particles using the ContactPoint from the OnCollisionEnter method that OnTriggerEnter doesn't have access to. I tried to simulate this ContactPoint using raycasts, but no luck. Could rewrite the code from scratch, but only if there's no other way...

There's this video where the guy has the same setup as my projectile, rigidbody and collider, yet, the projectile doesn't push the other object, but he doesn't go deeper on its behavior.

Any ideas?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You'll need to keep the velocity, angular velocity, and position every frame, then add some code to OnCollisionEnter in which you tell the two colliders to ignore each other from now on, and also restore the projectile's original velocity, angular velocity and position.

    private Collider col;
    private Rigidbody rigidBody;
    private Vector3 vel;
    private Vector3 angularVel;
    private Vector3 position;

    private void Start() {
        col = gameObject.GetComponent<Collider>();
        rigidBody = gameObject.GetComponent<Rigidbody>();
    }

    private void FixedUpdate() {
        vel = rigidBody.velocity;
        angularVel = rigidBody.angularVelocity;
        position = transform.position;
    }

    private void OnCollisionEnter(Collision collision) {
        Physics.IgnoreCollision(col, collision.collider);
        rigidBody.velocity = vel;
        rigidBody.angularVelocity = angularVel;
        transform.position = position;
    }
over 4 years ago · Santiago Trujillo Denunciar

0

In Edit -> Project Settings -> Physics, you will find the Layer Collision Matrix at the bottom. Here you can choose which layers collide with which layers. The default layer for gameobjects is "Default". Assign a new layer to your projectiles and the gameobjects you don't want collisions with. Then you can uncheck the box that represents these two layers in the Layer Collision Matrix. Now these gameobjects will not affect each other when colliding and methods like OnCollisionEnter will not be called for them. Hope this answers your question fully.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda