Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Detect incoming collisions?

Discussion in 'Scripting' started by DiamondWolf2, Aug 15, 2019.

  1. DiamondWolf2

    DiamondWolf2

    Joined:
    Dec 9, 2018
    Posts:
    16
    I'm trying to make an explosion. It works mostly as intended, however making the explosion ignore the player collider on collision enter still leaves a frame where the player reacts as though the explosion were a solid sphere. How would I fix this?

    In a similar vein, is there a way to make certain objects behave as though they were not solid while still calling OnCollision and variants? Due to the fact that the objects (mainly weapon projectiles) that need to behave this way are often the things that are moving, making them triggers is out of the question, since triggers only fire when things move into them, not when they move into the things.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Try triggers.
     
  3. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    There's also raycasts / spherecasts that could work, but honestly it's most of the time a pain to implement.
     
  4. DiamondWolf2

    DiamondWolf2

    Joined:
    Dec 9, 2018
    Posts:
    16
    As I said, the thing that would be a trigger is moving. From experience that doesn't work.

    Some form of cast might work though.
     
  5. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Why are you using collider for explosion in the first place? In my past project we had exploisons. I've just Physics.OverlapSphere and kick ass everything within. Everything else are just visuals. If your really need to simulate exploison pressure expansion in real time, then you can calculate delays and forces as a function of the distance to the center.
    Anyway, if you make explosion a trigger and use OnTriggerEnter on victims, it should work. If not, then you must be doing something wrong. Post you code and setup and we'll try to help.
     
  6. Nanior

    Nanior

    Joined:
    May 4, 2019
    Posts:
    101
    You can try:
    void OnTriggerEnter(Collider other){ } is when a istrigger collider in your collider
    void OnTriggerStay (Collision other){ }is when a not istrigger collider hit on your collider
     
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,616
    Did you also put a rigidbody on the moving object?
     
  8. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Set the projectile mass to a very small value, that way it won't be noticable.