Example #1
0
        public override MovementOutput GetMovement()
        {
            RaycastHit hit;

            MovementOutput movementOutput = new MovementOutput();
            Color          mainRayColor   = Color.white;
            Color          leftRayColor   = Color.white;
            Color          rightRayColor  = Color.white;

            /*
             * if (this.Character.velocity.magnitude == 0)
             * {
             *  return movementOutput;
             * }
             */

            Ray mainRay = new Ray(this.Character.Position, this.Character.velocity.normalized);
            //                                                                  +-45 graus
            const float Degrees45    = (float)0.52359877559;
            Vector3     leftWhisker  = MathHelper.Rotate2D(this.Character.velocity, -Degrees45);
            Vector3     rightWhisker = MathHelper.Rotate2D(this.Character.velocity, Degrees45);
            Ray         leftRay      = new Ray(this.Character.Position, leftWhisker.normalized);
            Ray         rightRay     = new Ray(this.Character.Position, rightWhisker.normalized);

            bool collision = false;

            //Check Collisions
            if (ObstacleCollider.Raycast(mainRay, out hit, this.MaxLookAhead))
            {
                mainRayColor = Color.red;
                collision    = true;
            }
            else if (ObstacleCollider.Raycast(leftRay, out hit, this.MaxLookAhead / 2))
            {
                leftRayColor = Color.red;
                collision    = true;
            }
            else if (ObstacleCollider.Raycast(rightRay, out hit, this.MaxLookAhead / 2))
            {
                rightRayColor = Color.red;
                collision     = true;
            }


            if (collision)
            {
                base.Target.Position = hit.point + hit.normal * this.AvoidMargin;
                //??base.Target.Position.y = 0;
                movementOutput          = base.GetMovement();
                movementOutput.linear.y = 0;
            }

            Debug.DrawRay(this.Character.Position, this.Character.velocity.normalized * this.MaxLookAhead, mainRayColor);
            Debug.DrawRay(this.Character.Position, leftWhisker.normalized * this.MaxLookAhead / 3, leftRayColor);
            Debug.DrawRay(this.Character.Position, rightWhisker.normalized * this.MaxLookAhead / 3, rightRayColor);

            return(movementOutput);
        }
Example #2
0
    /*
     * Collision handler. Here we notify collisioned elements and also apply changes in our player and game controller
     */
    void OnTriggerEnter(Collider other)
    {
        GameObject go = other.gameObject;

        if (go.tag == BaseValues.TAG_ORB_PICKUP)
        {
            _gameController.PickUpOrb();
            _fx.PickUpFX();
        }
        else if (go.tag == BaseValues.TAG_OBSTACLE && !_isInvincible)
        {
            Obstacle obstacleComp = go.GetComponent <Obstacle>();

            if (obstacleComp != null)
            {
                _gameController.RegisterDamage(obstacleComp.Damage);
            }
            else
            {
                ObstacleCollider colliderComp = go.GetComponent <ObstacleCollider>();
                _gameController.RegisterDamage(colliderComp.Damage);
            }

            AudioManager.GetCharFX().Damage();
            _fx.Damage();

            if (_gameController.GetCurrentHP() > 0)
            {
                _anim.Damage();

                if (_gameController.GetCurrentHP() == 1)
                {
                    _fx.SetLowLife(true);
                }

                _isInvincible = true;
            }
            else
            {
                _fx.CreateHitsFX();
                EndGame();
            }
        }
        else if (go.tag == BaseValues.TAG_GOAL)
        {
            EndGame(true);
        }

        /*
         * SendMessage without receiver required, this way we wont have errors if no receiver is previously prepared in collisioned object
         */
        go.SendMessage(BaseValues.RECEIVER_COLLISION_DETECTED, SendMessageOptions.DontRequireReceiver);
    }