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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Collision Problem

Discussion in 'Scripting' started by gmarquesDaniel, Nov 7, 2019.

  1. gmarquesDaniel

    gmarquesDaniel

    Joined:
    Oct 16, 2019
    Posts:
    4
    So, im trying to build a bomberman game from zero to practice and get familiarized with unity, i have walls which are indestructible and boxes which bombs can destroy. When a bomb explodes it creates explosions around it where theres no walls.

    upload_2019-11-7_12-29-48.png

    Im doing this, but for some reason its detecting collision with layers that are not "blockingLayer".


    Edit: so i discovered that this collision was working actually, but the explosion was being instantiated under the box, therefore i couldnt see it.

    But now theres a new problem, the explosion is instantiated on the same position as the box, how do i detect this collision? i was trying to do this, but it doesnt seem to work:

    upload_2019-11-7_13-51-20.png
     

    Attached Files:

    Last edited: Nov 7, 2019
  2. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    maybe blockingLayer is an integer index instead of a layer mask can someone explain him how to convert? Don't remember right now its something like 0x01 << blockingLayer

    edit:
    try ((int) 0x01 << blockingLayer) in the linecast method not sure if that's correct but should solve it
    edit2:

    linecast(....,((int) 0x01 << blockingLayer) );
     
    Last edited: Nov 7, 2019
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    Not sure, but I find the easiest thing to do is just declare a public LayerMask member variable, then you can just select which layers I want in the inspector.

    Use the LayerMask variable as a parameter in the LineCast method, and the implicit cast from LayerMask to int will automatically get you the correct value.
     
  4. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    nice didn't know that.

    So he had to use LayerMask instead of an int value, if we assume blockingLayer is a plain int
     
  5. gmarquesDaniel

    gmarquesDaniel

    Joined:
    Oct 16, 2019
    Posts:
    4
    I think im already doing that:

    upload_2019-11-7_13-21-19.png
     
  6. gmarquesDaniel

    gmarquesDaniel

    Joined:
    Oct 16, 2019
    Posts:
    4
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    Well, the parameter is an int value either way. I was just suggesting to use the LayerMask because that will automatically give you the correct value, rather than having to figure it out yourself. You don't have to use a LayerMask- it's just a matter of convenience.
     
  8. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    Not sure why it's not working, then. Have you used debug.log to find out what the line cast is actually hitting?
     
  9. gmarquesDaniel

    gmarquesDaniel

    Joined:
    Oct 16, 2019
    Posts:
    4
    Kinda, what exactly should i watch while debugging?
     
  10. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    The name and layer of the object? Just so you know for sure that what your LineCast is hitting is what you think it's hitting.