// TrueSyncBehaviour's interface public override void OnSyncedUpdate() { base.OnSyncedUpdate(); if (!m_Running) { return; } FP area = m_Width * m_Height; if (area <= FP.Zero) { return; } FP deltaTime = TrueSyncManager.deltaTimeMain; TSVector2 center = tsTransform2D.position; TSCollider2D[] colliders = TSPhysics2D.OverlapBoxAll(center, size, m_Angle, m_LayerMask); if (colliders != null) { if (colliders.Length > 0) { for (int index = 0; index < colliders.Length; ++index) { TSCollider2D currentCollider = colliders[index]; if (currentCollider == null) { continue; } TSRigidBody2D rigidbody = currentCollider.GetComponent <TSRigidBody2D>(); if (rigidbody != null) { // Drag TSVector2 currentVelocity = rigidbody.velocity; currentVelocity *= FP.One / (FP.One + (deltaTime * m_Drag)); rigidbody.velocity = currentVelocity; // Force FP angle = MathFP.ClampAngle(m_ForceAngle, FP.Zero, 360f); TSVector2 forceDirection = TSVector2.right; forceDirection = forceDirection.Rotate(angle); rigidbody.AddForce(forceDirection * m_ForceMagnitude); } } } } }
// TrueSyncBehaviour's interface public override void OnSyncedTriggerStay(TSCollision2D i_Collision) { base.OnSyncedCollisionStay(i_Collision); GameObject otherGo = i_Collision.gameObject; if (otherGo == null) { return; } bool valid = ValidateGameObject(otherGo); if (!valid) { return; } if (m_Running) { FP deltaTime = TrueSyncManager.deltaTimeMain; TSRigidBody2D rigidbody = otherGo.GetComponent <TSRigidBody2D>(); if (rigidbody != null) { // Drag TSVector2 currentVelocity = rigidbody.velocity; currentVelocity *= FP.One / (FP.One + (deltaTime * m_Drag)); rigidbody.velocity = currentVelocity; // Force FP angle = MathFP.ClampAngle(m_ForceAngle, FP.Zero, 360f); TSVector2 forceDirection = TSVector2.right; forceDirection = forceDirection.Rotate(angle); rigidbody.AddForce(forceDirection * m_ForceMagnitude); } } }