Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

2D Fast moving object with continuous detection still passing through another object.

Discussion in 'Physics' started by cjddmut, Dec 26, 2014.

  1. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    I have two objects, both with rigidbody2Ds and both have continuous detection turned on. The square object is doing all of it's movement by rigidbody2D.MovePosition(). However, at fast speeds I will still have issues with the object passing through another object.

    http://i.imgur.com/ZfS53Qg.gifv

    If it's relevant, they collide with each other using triggers that are on a child object (child objects do not have a rigidbody2D).

    I'm hoping to solve this without doing my own BoxCast when I use MovePosition so hoping that I'm missing something or some setting.

    Thanks!
    C.J.
     
  2. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    Ok, no response :p. I'm trying to figure out if some of the Physics2DSettings can be tweaked to give me better results. However, I can't really tell what they do. Position Iterations sounds plausible to something I might want to tweak but I see no difference regardless of what value I place.

    I don't see a hit in performance either so I'm not sure what it does.
     
  3. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    I can resolve my paticular issue by increasing the fixed timestep to a much smaller number. This seems like a less ideal solution though. Is it a bug that my rigibodies are moving through each other even though both are set to continuous and are both only moved with rigidbody2D.MovePosition()?
     
    CoolWater likes this.
  4. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    I experimented around to try to determine exactly what was going on and I believe I have found the issue.

    If I have two continuous detection objects with two non-trigger colliders then they appropriately collide when attempt to move fast past each other. However, if they are triggers instead, the trigger fails to detect. It's only when moving fast, if I move them slowly into each other then the triggers do detect.

    It looks like continuous detection only works for non-trigger colliders and is still discrete for trigger colliders. Is this by design or a bug?
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    in the rigidbody properties, try setting interpolate or extrapolate. i believe those might give a better result

    wish i had more help to offer x
     
  6. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    I think, I might be wrong, but those settings don't impact collision detecting and just smoothing the visual in between frames :(
     
  7. skusku

    skusku

    Joined:
    Jan 4, 2015
    Posts:
    17
    I think people should be aware of the fact that this is a physics engine, designed for simulating a great variety of physical behaviours but still being limited. Collision detection on objects with high relative velocity have, afaik, always been troublesome and will still be present in PhysX 3.

    Some brainstorming: instead of a trigger collider, cast a ray in the direction of your velocity, multiply that by an arbitrary number and you should get a much more stable collision detection.
    If this does not give you the desired precision, you could try changing the trigger collider's size based on your velocity vector. This should give your trigger collider a bigger timestamp to work with.

    good luck
     
  8. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    101
    The issue appears to be that continuous detection works for colliders but not triggers.That looks like a bug to me :) Having a faster time step has fixed the issue for me without bring too much of a hit to my performance. If I end up not being able to rely on that then I imagine I can do my own box casting to get me a good enough solution.