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

Detecting collisions without rigidbody

Discussion in 'Scripting' started by kamkaskan, Dec 26, 2015.

  1. kamkaskan

    kamkaskan

    Joined:
    Dec 17, 2015
    Posts:
    4
    Hello, I'm trying to create script that will connect walls object by changing the sprite of the wall object.
    For every wall I created 4 children with box colliders (Up, Down, Left, Right) to check if wall is near another object with wall tag.

    But there's my problem, I know how to check collisions and collider tag using OnCollisionEnter but I heard that it won't work when there's no rigidbody in any of the objects. And creating 4x rigidbody for object which will be multiplied hundred times on one scene is IMO bad option.

    Any solution?
     
    Bakanovskiy95 and TechRoxx5 like this.
  2. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    To detect collisions, a minimum of one of the two objects in the collision need a rigidbody.
     
  3. kamkaskan

    kamkaskan

    Joined:
    Dec 17, 2015
    Posts:
    4
    Yeah, I know, but isn't adding rigidbody to hundreds objects in one scene a bad idea? Isn't there any better way of doing it?
     
  4. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    Adding a rigidbody to hundreds of objects is fine, it all depends on how you code the collisions and physics.

    Any Rigidbody/Physics stuff should be calculated in FixedUpdate() and not in Update()
     
    Bakanovskiy95 likes this.
  5. yum

    yum

    Joined:
    Oct 13, 2012
    Posts:
    4
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    to me this screams "raycast!!" rather than collisions... is this taking place in real time when the game is running (i.e. things change as the player plays) or is it within the "level generation" step right at the beginning?

    edit: hmm old thread, :rolleyes:
     
    AliReda likes this.
  7. appsy91

    appsy91

    Joined:
    Oct 29, 2019
    Posts:
    4
    Putting this here in case somebody else wants to try this :) -

    There is an option to add 'isTrigger' property in any collider and you can listen to TriggerEvent in your script. This will work without having a rigidbody at all. But you do need to have colliders on the objects that have to collide.
     
  8. the_Whizzkid

    the_Whizzkid

    Joined:
    Apr 15, 2020
    Posts:
    20
    Old threat, but shows up on google, and before others try like me for quite some time:
    As far as I know, you Do need a rigidbody. I tried again to make it work without now, but the Documentation (from 2019.4 and many others before) clearly states it does not work without rigidbodies. Are you sure you had no rididbody attached? In that case I would be very interested in more details how you made it work...
     
    Jeremy-Borton likes this.
  9. yzRambler

    yzRambler

    Joined:
    Jan 24, 2019
    Posts:
    37
    What about former version?