- Home /
Am missing collisions thanks to floating precision.
I was originally using a sweeptest, but am not right now. I coded my own collisions from scratch, but they work essentialy as a sweeptest. I just have one issue (that happens with the sweeptest as well): because of floats' imprecision, sometimes I miss collisions if the character keeps moving after colliding with a wall. I tried solving this problem by moving the character in the opposite direction before doing the sweeptest, and it works, but that causes other problems (like accidentaly colliding with thin objects behind you). So I decided that the best option was to simply have an offset between the wall and the character, always a small distance imperceptible to the eye but big enough to register the collisions. The problem is that my code isn't working. Look, am not going to show my full code because it´s too long and honestly you won't read it, but am not asking for anything that doesn´t work with a simple sweeptest (so do that if you need to). The only thing that am doing besides that is this: float hitDistance = movement.magnitude * closestT; (movement is the displacement vector and closestT is a float that ranges from 0-1. It's basically the collision time). Then I do this: movement = movement / movement.magnitude * hitDistance; //and then I just translate the object the movement.
So, is there an efficient way to create a small gap between the wall and the character? I was trying this: hitDistance = movement.magnitude * closestT - smallOffset; but obviously doesn´t work.
I don´t know why, but Unity answers isn´t registering some of the multiplications. Is hitDistance = movement.magnitude by closestT; and movement = movement / movement.magnitude by hitDistance.
Part of the Unity Answers markup syntax includes italicizing text between single asterisks (*). For example, *this text is italicized.*
By that same token, you can also italicize the text by using html-style blocks (<>) for the same effect. As an example of this, <i>this text is italicized.</i>
How did I get around it just now? HTML character codes:
* = *
< = <
> = >
Your answer

Follow this Question
Related Questions
How Precise is Random.Range? 1 Answer
Vector3 constructor precision 1 Answer
Question on scale of imported 3D models 1 Answer
float precision, wrong computations 1 Answer
Convert double to float for Vector3 1 Answer