public static void Update(ref BulletPhysicsComponent bpc) { foreach (var entry in _flippers) { PhyFlipper phyFlipper = entry.Value; phyFlipper._FlipperUpdate(ref bpc); // debug var dbg = EngineProvider <IDebugUI> .Get(); bool isChanged = false; float sa = phyFlipper._startAngle * 180.0f / Mathf.PI; float se = phyFlipper._endAngle * 180.0f / Mathf.PI; isChanged |= dbg.GetProperty(phyFlipper.dbgPropStartAngle, ref sa); isChanged |= dbg.GetProperty(phyFlipper.dbgPropEndAngle, ref se); if (isChanged) { phyFlipper._startAngle = sa * Mathf.PI / 180.0f; phyFlipper._endAngle = se * Mathf.PI / 180.0f; HingeConstraint hinge = (HingeConstraint)phyFlipper._constraint; if (phyFlipper.RotationDirection == 1) { hinge.SetLimit(phyFlipper._startAngle, phyFlipper._endAngle, 0.0f); } else { hinge.SetLimit(phyFlipper._endAngle, phyFlipper._startAngle, 0.0f); } } } }
/// <summary> /// Flipper rotation. /// Executed every physics simulation step. /// </summary> void _FlipperUpdate(ref BulletPhysicsComponent bpc) { _UpdateFlipperMass(ref bpc); float M = (float)(_usedFlipperMass * 1e7); float angle = _GetAngle(); float maxAngle = math.abs(_startAngle - _endAngle) * (180.0f / math.PI); float flipperOnForce = bpc.flipperAcceleration; float flipperOffForce = flipperOnForce * bpc.flipperSolenoidOffAccelerationScale; if (angle > (maxAngle - bpc.flipperNumberOfDegreeNearEnd) && SolenoidState == 1) { flipperOnForce *= bpc.flipperOnNearEndAccelerationScale; } if (angle < bpc.flipperNumberOfDegreeNearEnd && SolenoidState == -1) { flipperOffForce *= bpc.flipperOnNearEndAccelerationScale; } switch (SolenoidState) { case 1: body.ApplyTorque(new Vector3(0, 0, RotationDirection) * flipperOnForce * M); break; case -1: body.ApplyTorque(new Vector3(0, 0, -RotationDirection) * flipperOffForce * M); break; } }
public void Init(TableBehavior tableBehavior) { // add component if not already added in editor _component = tableBehavior.gameObject.GetComponent <BulletPhysicsComponent>(); if (_component == null) { _component = tableBehavior.gameObject.AddComponent <BulletPhysicsComponent>(); } _component.Initialize(); _component.PrepareTable(); }
void _UpdateFlipperMass(ref BulletPhysicsComponent bpc) { // Update params from ImGui menu float newMass = math.pow(10.0f, bpc.flipperMassMultiplierLog); if (newMass != _prevFlipperMassMultiplierLog) { _prevFlipperMassMultiplierLog = newMass; _usedFlipperMass = Mass * _prevFlipperMassMultiplierLog; Vector3 inertia = body.CollisionShape.CalculateLocalInertia(_usedFlipperMass); body.SetMassProps(_usedFlipperMass, inertia); } }