private void DoForces(Rigidbody2D body, LightEdge edge, RotatableLight.RotationConstraints constraints) { var edgeAccel = edge.GetAppliedAngularAcceleration(); var accelTowardsCenter = edge.GetAppliedAccelTowardsCenter(); //if (edgeAccel != 0) { // Debug.Log("Edge accel: " + edgeAccel); // Debug.Log("Central Force" + accelTowardsCenter); //} LightSettings s = settings; edge.SetInertia(s.inertia); var accel = -edge.GetAppliedAngularAcceleration() * s.mult; //accel = Mathf.Sign(accel) * Mathf.Sqrt(Mathf.Abs(accel)); accelTowardsCenter *= s.centralAccelerationConstant; accel = Mathf.Sign(accel) * (Mathf.Abs(accel) + Mathf.Abs(accelTowardsCenter)); accel = Mathf.Clamp(accel, -s.maxAccel, s.maxAccel); if (Mathf.Abs(accel) < s.minAccel) { accel = 0; } body.rotation -= Mathf.Clamp(edge.AngularDifferenceFromTarget() * s.resolveConstant, -s.maxResolve, s.maxResolve); constraints.Apply(body); body.AddTorque(accel * body.inertia); }
public void ApplyForces(Rigidbody2D body, LightEdge rightShadowEdge, LightEdge leftShadowEdge, RotatableLight.RotationConstraints constraints) { DoForces(body, rightShadowEdge, constraints); DoForces(body, leftShadowEdge, constraints); }