// INTERNALS public void UpdateEffector() { TSCollider2D[] colliders = TSPhysics2D.OverlapCircleAll(tsTransform2D.position, m_Radius, 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; } TSTransform2D transform2d = currentCollider.tsTransform; TSVector2 direction = transform2d.position - tsTransform2D.position; direction = direction.normalized; TSRigidBody2D rigidbody = currentCollider.GetComponent <TSRigidBody2D>(); if (rigidbody != null) { rigidbody.AddForce(direction * m_ForceMagnitude); } } } } }
// MonoBehaviour's INTERFACE void Awake() { m_Collider2D = GetComponent <TSCollider2D>(); // Set sort order. sortOrder = BehaviourSortOrder.s_SortOrder_Goal; }
// MonoBehaviour's interface private void Awake() { m_Collider = GetComponent <TSCollider2D>(); m_Rigidbody = GetComponent <TSRigidBody2D>(); // Set sort order. sortOrder = BehaviourSortOrder.s_SortOrder_HoleTarget; }
public TSRaycastHit2D(TSCollider2D i_Collider, TSVector2 i_Point, TSVector2 i_Normal, FP i_Distance, FP i_Fraction) { m_Collider = i_Collider; m_Point = i_Point; m_Normal = i_Normal; m_Distance = i_Distance; m_Fraction = i_Fraction; }
// MonoBehaviour's INTERFACE void Awake() { // Cache components. { m_Rigidbody2D = GetComponent <TSRigidBody2D>(); m_Collider2D = GetComponent <TSCollider2D>(); m_CharacterInput = GetComponent <tnCharacterInput>(); m_StatsContainer = GetComponent <tnStatsContainer>(); m_Energy = GetComponent <tnEnergy>(); m_Respawn = GetComponent <tnRespawn>(); } // Init data. { m_OriginalLayer = gameObject.layer; m_DashLayer = LayerMask.NameToLayer("Charging"); } // Force values refresh. { ComputeAppliedForce(FP.Zero); ComputeMass(FP.Zero); ComputeDrag(FP.Zero); ComputeMaxSpeed(FP.Zero); ComputeDashMass(FP.Zero); ComputeDashDrag(FP.Zero); ComputeDashAppliedForce(FP.Zero); ComputeDashCooldown(FP.Zero); ComputeDashDuration(FP.Zero); ComputeDashEnergyCost(FP.Zero); } // Set sort order. sortOrder = BehaviourSortOrder.s_SortOrder_CharacterController; }
public TSRaycastHit2D(TSCollider2D collider) { this.collider = collider; this.rigidbody = collider.GetComponent <TSRigidBody2D>(); this.transform = collider.GetComponent <TSTransform2D>(); }
// INTERNALS private bool Kick(LayerMask i_Mask, FP i_AppliedForce, FP i_DeltaTime, bool i_InvertVelocity = false) { bool kickedAnything = false; TSCollider2D[] colliders = TSPhysics2D.OverlapCircleAll(tsTransform2D.position, m_Radius, i_Mask); if (colliders != null) { for (int colliderIndex = 0; colliderIndex < colliders.Length; ++colliderIndex) { TSCollider2D currentCollider = colliders[colliderIndex]; if (currentCollider == null) { continue; } GameObject currentGo = currentCollider.gameObject; if (m_CharacterController != null) { int currentLayer = m_CharacterController.currentLayer; if (currentLayer == m_ChargingLayer) { continue; } } tnKickable kickable = currentGo.GetComponent <tnKickable>(); if (kickable == null) { continue; } TSTransform2D kickableTransform = kickable.tsTransform2D; if (kickableTransform == null) { continue; } TSVector2 kickablePosition = kickableTransform.position; kickedAnything = true; // Evaluate force. TSVector2 direction = kickablePosition - tsTransform2D.position; direction.Normalize(); TSVector2 force = direction * i_AppliedForce; if (i_InvertVelocity) { if (i_DeltaTime > FP.Zero) { FP otherMass = kickable.mass; TSVector2 otherVelocity = kickable.currentVelocity; TSVector2 oppositeForce = (otherMass * otherVelocity) / i_DeltaTime; oppositeForce = oppositeForce * -FP.One; force += oppositeForce; } } // Kick. kickable.Kick(force, gameObject); // Notify listeners. if (m_KickEvent != null) { m_KickEvent(kickable); } } } return(kickedAnything); }