This project has moved and is read-only. For the latest updates, please go here.

TimeOfImpact.CalculateTimeOfImpact returns TOIOutputState.Seperated even though the sweep overlaps the edge

Topics: User Forum
Aug 22, 2014 at 11:42 AM
Edited Aug 22, 2014 at 11:43 AM
I'm doing a custom shapecast by using Broadphase.Query then calculating the TOI of overlapping AABBs. The caster is a CircleShape, all other shapes are ChainShapes.
The goal is to detect contact with single-sided chains: traverse (ignore) the edge when going up, stick to the edge when going down.

Sometimes I end up with the end position of the sweep just barely touching an edge, but still I get TOIOutputState.Seperated (with a T of 1, which AFAIU is the TMax I input). So I discard the edge, and the cast fails.
Then on the next frame, the cast succeeds right away (TOI 0 or so), but I discard the edge anyway because hey, my start and end pos are both below the edge.

See screencaps below: at frame 16386 (yellow one), the circle, representing the end position of the cast, touches the edge, but as indicated by the log the state is Seperated.
The top of the vertical lines is the cast center positions, the diamond shape represents the feet position of the player.


This might sound like bad luck, but still at 60 FPS it does happens (like 1 out of 100).

I understand there are tolerances involved, and I can hack around the issue, but I feel like I'm missing something: how can CalculateTimeOfImpact fail when a contact obviously occurs (start pos on one side of the edge, end pos on the other).
The case of returning Seperated is in TimeOfImpact.cs, line 376, and the comment says "Victory!": whaaat?

I hope I'm making sense, I feel like I'm struggling to describe something that's relatively simple :( !
BTW, a look at the game: (at the very bottom - is there no way to permalink to a particular post on Codeplex? just the whole thread?)