0

So right now I am stuck. I want to make a conveyor belt with my code but I ran inot this problem. I found this piece of code,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ConveyorPush : MonoBehaviour {
    public float speed = 3.0f;
    void OnTriggerStay(Collider other) {

        // Assign velocity based upon direction of conveyor belt
        // Ensure that conveyor mesh is facing towards its local Z-axis
        float conveyorVelocity = speed * Time.deltaTime;
        Rigidbody rigidbody = other.gameObject.GetComponent<Rigidbody>();
        rigidbody.velocity = conveyorVelocity * transform.forward;
    }
}   

I understand it but for some reason my trigger collider on the conveyor belt is not detecting a collision to a sprite with a non-trigger collider that has a rigid body.

Ancient Bison
  • 43
  • 1
  • 10
  • Does this answer your question? [Collision detection not working unity](https://stackoverflow.com/questions/43939179/collision-detection-not-working-unity) – Ruzihm Nov 04 '20 at 22:19

1 Answers1

-1
    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.collider.tag == "Obstacle")
        {
            movement.enabled = false;
            FindObjectOfType<GameManager>().GameOver();
            rb.useGravity = false;
            rb.AddExplosionForce(1000,transform.position, 200);
        }

    }

When you defined collider in the function u didn't use it anywhere

If your using 2d then u should use the 2d collider

    void OnCollisionEnter(Collision2D collisionInfo)
    {
        if (collisionInfo.collider.tag == "Obstacle")
        {
            movement.enabled = false;
            FindObjectOfType<GameManager>().GameOver();
            rb.useGravity = false;
            rb.AddExplosionForce(1000,transform.position, 200);
        }

    }

Collision and Collision2D are types u have to define