Closed Atomiz2002 closed 1 year ago
Rb2D.velocity
is Vector2.zero
in some cases (ie. not a valid direction), and I don't handle this.
I've just pushed an update that handles it, 2.1.2
. It should arrive in OpenUPM soon.
It seems it still appears... at the exact same place, and from my experiments it doesnt seem like its just because of the velocity being zero.
I can't seem to replicate this unless I pass NaN
into direction
or angle
from outside.
Is there any indication of where/how NaN is being introduced into this codepath for you? If you use the debugger in the CapsuleCast2D:Draw (Shapes.Casts2D.cs:460) method, can you see where NaN gets created when this occurs?
Otherwise I could write some code to protect against it, but it's hard to make it reasonable without knowing what's introducing NaN in the first place.
I've pushed 2.1.3 which should at least silently handle this case.
Vector2 velocity = Rb2D.velocity * Mathf.Max(0f, 1f - .5f * Time.fixedDeltaTime);
Origin = Rb2D.position + velocity *
Time.fixedDeltaTime + velocity.normalized *
(RaycastLength / 2 - RaycastRadius / 2);
Size = new(RaycastRadius, RaycastLength);
CapsuleDirection = CapsuleDirection2D.Vertical;
Angle = Mathf.Atan2(velocity.y, velocity.x) * Mathf.Rad2Deg + 90;
Direction = velocity;
Distance = RaycastDistance;
LayerMask = Layers.Ground;
Debug.Log($"{float.IsNaN(Angle)}");
Shapes.Casts.2D.cs
Shapes.cs
To me it really seems the issue is that dotA
sometimes results in a value < -1, which results in NaN (https://learn.microsoft.com/en-us/dotnet/api/system.mathf.acos?view=net-7.0#returns the unity docs dont really note that, but it might be applicable there too, not sure). I checked the value of dotA when the error was not occuring and it was always either -1 or -0.9948...smth. I have no clue why it doesn't seem to appear for dotB in Arc arcA = ...
but it might be irrelevant.
Note: this is on v2.1.2
This helps a lot, and makes total sense now thanks! Now I can fix it properly haha. The current release should hopefully be functional, but a future release will fix it properly.
Error 1
Quaternion To Matrix conversion failed because input Quaternion is invalid {-nan(ind), -nan(ind), -nan(ind), -nan(ind)} l=-nan(ind) UnityEngine.Matrix4x4:TRS (UnityEngine.Vector3,UnityEngine.Quaternion,UnityEngine.Vector3) Vertx.Debugging.Shape/Arc:.ctor (UnityEngine.Vector3,UnityEngine.Quaternion,single,Vertx.Debugging.Shape/Angle) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.cs:528) Vertx.Debugging.Shape/Arc:.ctor (UnityEngine.Vector2,single,single,Vertx.Debugging.Shape/Angle) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.cs:533) Vertx.Debugging.Shape/CapsuleCast2D:Draw (Vertx.Debugging.CommandBuilder,UnityEngine.Color,UnityEngine.Color,single) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.Casts.2D.cs:516) Vertx.Debugging.Shape/CapsuleCast2D:Draw (Vertx.Debugging.CommandBuilder,UnityEngine.Color,single) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.Casts.2D.cs:455) Vertx.Debugging.D:rawError 2
Quaternion To Matrix conversion failed because input Quaternion is invalid {nan, nan, nan, nan} l=nan UnityEngine.Matrix4x4:TRS (UnityEngine.Vector3,UnityEngine.Quaternion,UnityEngine.Vector3) Vertx.Debugging.Shape/Arc:.ctor (UnityEngine.Vector3,UnityEngine.Quaternion,single,Vertx.Debugging.Shape/Angle) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.cs:528) Vertx.Debugging.Shape/Arc:.ctor (UnityEngine.Vector2,single,single,Vertx.Debugging.Shape/Angle) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.cs:533) Vertx.Debugging.Shape/CapsuleCast2D:Draw (Vertx.Debugging.CommandBuilder,UnityEngine.Color,UnityEngine.Color,single) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.Casts.2D.cs:517) Vertx.Debugging.Shape/CapsuleCast2D:Draw (Vertx.Debugging.CommandBuilder,UnityEngine.Color,single) (at Library/PackageCache/com.vertx.debugging@2.1.1/Runtime/Shapes/Shapes.Casts.2D.cs:455) Vertx.Debugging.D:raw