CollisionShape _AddGateWire(GateBehavior gate, GateWireBehavior wire) { var gt = gate.gameObject.transform; var wireMeshe = wire.gameObject.GetComponentsInChildren<MeshFilter>(true)[0]; var meshSize = wireMeshe.mesh.bounds.size * gt.localScale.z; _thickness = meshSize.y; _length = meshSize.x; _barHeight = meshSize.z; base.offset = new Vector3(0, 0, _barHeight * 0.70f); return new BoxShape(_length * 0.5f, _thickness * 0.5f, _barHeight * 0.25f); // bar = 30% of height }
public PhyGate(GateBehavior gate, GateWireBehavior wire) : base(PhyType.Gate) { Mass = 0.4f; // why gates don't have mass? _rotation = gate.data.Rotation.ToRad(); _startAngle = gate.data.AngleMin - 10.0f.ToRad(); _endAngle = gate.data.AngleMax + 10.0f.ToRad(); _type = gate.data.TwoWay ? GateType.TwoWay : GateType.OneWay; //s_type = GateType.TwoWays; if (_type == GateType.TwoWay) _startAngle = -_endAngle; //RotationDirection = flipper.data.StartAngle > flipper.data.EndAngle ? -1 : 1; //_height = flipper.data.Height; //_startAngle = flipper.data.StartAngle * Mathf.PI / 180.0f; //_endAngle = flipper.data.EndAngle * Mathf.PI / 180.0f; SetupRigidBody(Mass, _AddGateWire(gate, wire)); SetProperties( Mass, gate.data.Friction, gate.data.Elasticity * 100.0f); body.SetDamping(gate.data.Damping, gate.data.Damping); // calc position of wire like from gate Matrix4x4 m = Matrix4x4.TRS( gate.gameObject.transform.localPosition, gate.gameObject.transform.localRotation, UnityEngine.Vector3.one ); // wire is drawed as child of gate, so position & rotation is relative to gate // we need also calc transformation from physics coords system to "gate relative" coords var m2 = m; m *= Matrix4x4.Translate(-offset.ToUnity()); base.matrix = m.ToBullet(); base.localToWorld = m2.inverse; base.name = gate.name; base.entity = Entity.Null; }