Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How can i keep the player rolling instead of hitting on object and slowing down?

Discussion in 'Scripting' started by superdoesthings, May 19, 2023.

  1. superdoesthings


    May 17, 2023
    I want to make the player not stop and hit the food and slow down, then clip through it, I want the player to instantly go through the food and a point be given (code below). I want the food to visually disappear after it gets hit, too.

    collision script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class collide : MonoBehaviour
    void OnCollisionEnter (Collision collision)
    if (collision.collider.tag == "lazer"){
    //add respawn later

    if (collision.collider.tag == "food"){
    //add a point
  2. Yoreki


    Apr 10, 2019
    Triggers work like collisions but without involving physics. Basically collision detection without handling.

    You could handle your food with triggers. For that you need the collider to the set to isTrigger=True. Also, try abstracting from your problem to be better able to search for solutions. Effectively you want to collect items. That is done in millions of games, so there is hundreds of tutorials on it, like this one:

    Also, there are collision layers for similar what-collides-with-what usecases, but that's more helpful for generally ignoring collisions with certain objects

    In the future please use code tags to include code examples.
    Last edited: May 19, 2023