Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Velocity and onTriggerEnter Problem

Discussion in '2D' started by gurselgazi, Aug 13, 2019 at 6:10 PM.

  1. gurselgazi

    gurselgazi

    Joined:
    Feb 14, 2018
    Posts:
    5
    Hi guys,
    I'm developing a mobile game where player moves to the x direction just by velocity. And I'm having a little problem. When velocity going too high, player's collider not triggering the enemy triggerenter event because player cannot be seen because of it. How can prevent that? How can I move too fast but still seen and trigger the event?
     
  2. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,539
    Use Collision Detection: Continuous on the Rigibody2D.
     
    Last edited: Aug 13, 2019 at 7:58 PM
  3. gurselgazi

    gurselgazi

    Joined:
    Feb 14, 2018
    Posts:
    5
    It didn't work. And if I disable Trigger and use colliderEnter then I can't get through the object. it just collides and stays.
     
  4. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,539
    Ah I'm sorry, I forgot that Continuous collision doesn't work with triggers.

    You could try doing your own checks each FixedUpdate using Rigidbody.Cast to sweep the player's collision shape in front of the player by their velocity and detect what they will overlap in the next movement.

    https://docs.unity3d.com/ScriptReference/Rigidbody2D.Cast.html
     
    MelvMay likes this.
  5. gurselgazi

    gurselgazi

    Joined:
    Feb 14, 2018
    Posts:
    5
    It worked that way but I have another problem. I just wanna trigger once but player gets through the object it triggers multiple times.
     
  6. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,539
    I'm not sure the exact reason that's happening, so it may be possible to fix the duplicates occurring.

    But in any case, would it be a simple solution to disable the trigger after it is detected the first time?
     
  7. gurselgazi

    gurselgazi

    Joined:
    Feb 14, 2018
    Posts:
    5
    The senario is that I have an object and it has health, I want to go through that object multiple times but in this case, when I'm getting through that object collision happens all the time when player is in the object that's why it happens multiple times. I just wanna detect collision enter but raycasthit2d doesn't have anything like that or I couldn't findt it.
     
  8. gurselgazi

    gurselgazi

    Joined:
    Feb 14, 2018
    Posts:
    5
    [SOLVED]
    I made it rigidbody kinetic and disabled the trigger while enable use full kinematic contacts for both player and object. collision works that way and I can go faster, detect collision and get through the object.