Beispiel #1
0
    /**
     * @brief Check which gameobject the ball has collided and changes the movement accordingly.
     **/
    public void OnSyncedTriggerEnter(TSCollision2D other)
    {
        // if hits horizontal colliders then inverse X axis movement
        if (other.gameObject.tag == "GroundHor")
        {
            speedX *= -1;
            // if hits vertical colliders then inverse Y axis movement
        }
        else if (other.gameObject.tag == "GroundVer")
        {
            // As the ball is moving down and hits the collider then the player on top side should score
            if (speedY < 0)
            {
                CallPaddleScore(true);
                // As the ball is moving up and hits the collider then the player on bottom side should score
            }
            else
            {
                CallPaddleScore(false);
            }

            speedY *= -1;
            // if hits a paddle then should also inverse Y axis movement
        }
        else
        {
            // Check to avoid movement change when the ball hits the paddle by its back
            if (speedY * tsRigidBody.position.y > 0)
            {
                speedY *= -1;
            }
        }
    }
Beispiel #2
0
 /**
  * @brief When a ball hits this goal the score is updated and a 'GoalScored' is triggered.
  **/
 public void OnSyncedTriggerEnter(TSCollision2D otherBody)
 {
     if (otherBody.gameObject.name == "Ball")
     {
         score++;
         UpdateScore();
         otherBody.gameObject.SendMessage("GoalScored");
         gameEndHandler.gameObject.SendMessage("GoalScored", this);
     }
 }
 public override void OnSyncedCollisionEnter(TSCollision2D i_Collision)
 {
     if (i_Collision.collider.CompareTag(Tags.s_Ball))
     {
         if (m_OnBallTouched != null)
         {
             m_OnBallTouched();
         }
     }
 }
Beispiel #4
0
 /**
  * @brief When the ball hits a player a force in Y axis is applied and also plays a sound when the collision is not with a goal.
  **/
 public void OnSyncedCollisionEnter(TSCollision2D other)
 {
     if (other.gameObject.tag == "player")
     {
         tsRigidBody2D.AddForce(new TSVector2(0, -500));
     }
     if (other.gameObject.tag != "goal")
     {
         audioSource.Play();
     }
 }
    public override void OnSyncedCollisionEnter(TSCollision2D i_Collision)
    {
        if (!m_TrackTouches)
        {
            return;
        }

        GameObject otherGo = i_Collision.gameObject;

        if (otherGo.CompareTag(Tags.s_Character))
        {
            InternalAddTouch(otherGo, TrueSyncManager.timeMain /* Timestamp */);
        }
    }
Beispiel #6
0
    // TrueSyncBehaviour's interface

    public override void OnSyncedTriggerEnter(TSCollision2D i_Collision)
    {
        if (!i_Collision.collider.CompareTag(Tags.s_Ball))
        {
            return;
        }

        if (m_TeamId == Hash.s_NULL)
        {
            return;
        }

        tnGoalEventParams goalEventParams = new tnGoalEventParams();

        goalEventParams.SetTeamId(m_TeamId);

        goalEventParams.SetHasValidScorer(false);

        {
            // Try to assign a valid scorer.

            tnKickable kickable = i_Collision.gameObject.GetComponent <tnKickable>();
            if (kickable != null)
            {
                for (int touchIndex = 0; touchIndex < kickable.touchesCount; ++touchIndex)
                {
                    tnTouch ballTouch = kickable.GetTouch(touchIndex);

                    if (m_TeamId != ballTouch.teamId)
                    {
                        goalEventParams.SetScorerId(ballTouch.characterId);
                        goalEventParams.SetScorerTeamId(ballTouch.teamId);

                        goalEventParams.SetIsHumanScorer(ballTouch.isHuman);
                        goalEventParams.SetIsLocalScorer(ballTouch.isLocal);

                        goalEventParams.SetHasValidScorer(true);

                        break;
                    }
                }
            }
        }

        // Send event.

        Messenger.Broadcast <tnGoalEventParams>("Goal", goalEventParams);
    }
 public override void OnSyncedCollisionExit(TSCollision2D i_Collision)
 {
     if (m_HitEffectTimer == 0f)
     {
         if (!i_Collision.collider.CompareTag(Tags.s_Ball))
         {
             if (m_DurationTimer > 0f)
             {
                 EffectUtils.PlayEffect(m_HitEffect, transform.position, transform.rotation);
                 m_HitEffectTimer = m_HitEffectInterval;
             }
         }
         else
         {
             EffectUtils.PlayEffect(m_BallHitEffect, transform.position, transform.rotation);
             m_HitEffectTimer = m_HitEffectInterval;
         }
     }
 }
    public override void OnSyncedCollisionExit(TSCollision2D i_Collision)
    {
        if (i_Collision.gameObject.CompareTag(Tags.s_Character))
        {
            if (m_HitEffectTimer == 0f)
            {
                EffectUtils.PlayEffect(m_CharacterHitEffect, transform.position, transform.rotation);

                m_HitEffectTimer = m_HitEffectInterval;
            }
        }
        else
        {
            if (m_HitEffectTimer == 0f)
            {
                EffectUtils.PlayEffect(m_HitEffect, transform.position, transform.rotation);

                m_HitEffectTimer = m_HitEffectInterval;
            }
        }
    }
    // TrueSyncBehaviour's INTERFACE

    public override void OnSyncedCollisionEnter(TSCollision2D i_Collision)
    {
        if (m_ScreenShake == null)
        {
            return;
        }

        GameObject colliderGo = i_Collision.collider.gameObject;

        bool validObject = colliderGo.CheckLayerMask(m_LayerMask);

        if (!validObject)
        {
            return;
        }

        float velocity2 = i_Collision.relativeVelocity.LengthSquared().AsFloat();

        float minThreshold2 = m_VelocityThresholdMin * m_VelocityThresholdMin;
        float maxThreshold2 = m_VelocityThresholdMax * m_VelocityThresholdMax;

        float velocityFactor = MathUtils.GetClampedPercentage(velocity2, minThreshold2, maxThreshold2);

        float shakeTime   = Mathf.Lerp(m_ShakeTimeMin, m_ShakeTimeMax, velocityFactor);
        float shakeAmount = Mathf.Lerp(m_ShakeAmountMin, m_ShakeAmountMax, velocityFactor);

        if (shakeTime < Mathf.Epsilon)
        {
            return;
        }

        if (shakeAmount < Mathf.Epsilon)
        {
            return;
        }

        m_ScreenShake.ForceShake(shakeTime, shakeAmount, m_ShakeMode, null);
    }
    public override void OnSyncedCollisionEnter(TSCollision2D i_Collision)
    {
        int tick = TrueSyncManager.ticksMain;

        // Apply forces.

        TSRigidBody2D rigidbody2D = i_Collision.gameObject.GetComponent <TSRigidBody2D>();

        if (rigidbody2D != null)
        {
            // Clear velocity.

            rigidbody2D.velocity = TSVector2.zero;

            // Add bounce force.

            TSVector2 otherPosition = rigidbody2D.position;
            TSVector2 myPostion     = tsTransform2D.position;

            TSVector2 direction = otherPosition - myPostion;
            direction.Normalize();

            TSVector2 force = direction * m_Force;

            rigidbody2D.AddForce(force);
        }

        // Play effect.

        if (!m_EffectTicks.Contains(tick))
        {
            m_Animator.SetTrigger("Hit");
            EffectUtils.PlayEffect(m_Effect, transform);

            m_EffectTicks.Add(tick);
        }
    }