Question was answered.
Why are my functions float parameters being set to 0 when 1 is passed as the argument value?
I was stepping through my C# script in Monodevelop and I noticed something odd. I am passing 2 floats named vt1 and vt2 into a method and in the debugger I can see that vt1 and vt2 are each of value 1 going in as you can see in the first image. Then once I step into the method, the corresponding parameters of the method aren't set to 1 but to 0 for both variables. The variable I am passing and the parameter name share the same name for simplicity. I have no idea why this is happening and it is causing problems because I use this value to ascertain distance and they keep getting zeroed, does anyone have any ideas why this is happening?
Also, any new float parameters I add to the function have the same effect and passing an argument by hardcoding a float in the call instead of a variable has the same effect.
This is the method being called inside a for loop.
BoxBoxIntersection (obj1, _objs[column], vt1, vt2, ref collision);
This is the method in question:
private void BoxBoxIntersection(Box2DPhysicsObject obj1, Box2DPhysicsObject obj2, float vt1, float vt2, ref Box2DCollision collision)
Before being called: Stepped into:
private void BoxBoxIntersection(Box2DPhysicsObject obj1, Box2DPhysicsObject obj2, float vt1, float vt2, ref Box2DCollision collision)
{
collision.axis = AxisSide.None;
collision.t = -1f;
collision.velocity1 = obj1.velocity;
collision.velocity2 = obj2.velocity;
if (obj1.velocity == obj2.velocity) {
return;
}
float bt1 = $$anonymous$$athf.$$anonymous$$ax(0, 1 - vt1);
Vector2 velocity1_2 = Time.deltaTime * vt1 * obj1.velocity;
Vector3 velocity1_3 = new Vector3(velocity1_2.x, velocity1_2.y, 1f);
Vector2 velocity2_2 = Time.deltaTime * vt2 * obj2.velocity;
Vector3 velocity2_3 = new Vector3(velocity2_2.x, velocity2_2.y, 1f);
for (int d = 0; d < 4; d++) {
BoxSide[] sides1 = obj1.GetSide ((AxisSide)d);
BoxSide[] sides2 = obj2.GetSide (OppositeSide((AxisSide)d));
for (int i = 0; i < sides1.Length; i++) {
for (int j = 0; j < sides2.Length; j++) {
float t = BoxBoxSideIntersection (sides1 [i], sides2 [j], velocity1_3, velocity2_3, (AxisSide)d);
if (t >= 0) {
t = $$anonymous$$athf.Clamp01 ((vt1 * t) + bt1);
if (collision.t < 0 || t < collision.t) {
collision.t = t;
collision.axis = (AxisSide)d;
ProcessBoxBoxCollision (obj1, obj2, ref collision);
}
}
}
}
}
}
Answer by Dankey_Kang · Oct 30, 2018 at 03:06 PM
It was because I was using MonoDevelop, I should have been using Visual Studio to debug and this appears to be a bug of some kind caused by going into a loop. I did fix my problem of debugging the my program by stepping into it earlier in the loop I was able to see correct behavior but somewhere along the line it must cause some problems with MonoDevelop that are not present in Visual Studio.