private Vector3 GetDirection()
 {
     // If the player is standing on a cloud, we recover the direction the cloud is moving in to decide the direction.
     if (_charCont.IsStandingOnCloud)
     {
         // Recover the newest cloud player is standing on
         if (_trackedCloud == null || _trackedCloud != _charCont.transform.parent.gameObject.GetComponent <MoveablePlatform>())
         {
             _trackedCloud = _charCont.transform.parent.gameObject.GetComponent <MoveablePlatform>();
         }
         return((_trackedCloud.MovingRight) ? Vector3.right : Vector3.left);
     }
     return((_charCont.MovementDirection == "left") ? Vector3.left : Vector3.right);
 }
Ejemplo n.º 2
0
    private void OnCollisionEnter(Collision collision)
    {
        allowToJump = false;
        if (collision.gameObject.CompareTag("Ground") ||
            collision.gameObject.CompareTag("MoveablePlatform") ||
            collision.gameObject.CompareTag("SwitchablePlatform"))
        {
            Rigidbody.velocity = Vector3.zero;
            var deformDirection = -collision.GetContact(0).normal;
            _deformation.Deform(deformDirection, 0.4f, 0.08f);
        }

        if (collision.gameObject.CompareTag("Enemy"))
        {
            Death();
        }

        if (collision.gameObject.CompareTag("MoveablePlatform"))
        {
            CalculateOffset(collision);

            MoveablePlatform moveablePlatform = collision.transform.GetComponentInParent <MoveByWaypoints>();
            if (moveablePlatform == null)
            {
                moveablePlatform = collision.transform.GetComponentInParent <Rotation>();
            }

            moveablePlatform.StartMovement();

            _isGroundedToMp = true;
        }

        if (collision.gameObject.CompareTag("Ice"))
        {
            Vector3 newVelocity = Rigidbody.velocity;
            Rigidbody.velocity = newVelocity.normalized * speed * Time.deltaTime * 0.75f;
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        // Check if the player has pressed the fire button and if enough time has elapsed since they last fired
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            // Update the time when our player can fire next
            nextFire = Time.time + fireRate;

            // Start our ShotEffect coroutine to turn our laser line on and off
            StartCoroutine(ShotEffect());

            // Create a vector at the center of our camera's viewport
            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            // Declare a raycast hit to store information about what our raycast has hit
            RaycastHit hit;


            // Set the start position for our visual effect for our laser to the position of gunEnd
            laserLine.SetPosition(0, gunEnd.position);

            // Check if our raycast has hit anything
            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                // if (Physics.SphereCast(rayOrigin, 100,fpsCam.transform.forward, out hit, weaponRange))

                // Set the end position for our laser line
                laserLine.SetPosition(1, hit.point);

                // Get a reference to a health script attached to the collider we hit
                ShootableBox     health = hit.collider.GetComponent <ShootableBox>();
                MovePlatform     mp     = hit.collider.GetComponent <MovePlatform>();
                MoveablePlatform mc     = hit.collider.GetComponent <MoveablePlatform>();
                MultiMove        mm     = hit.collider.GetComponent <MultiMove>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }

                if (mp != null)
                {
                    //use if MoveablePlatform is mine not prefab
                    mp.Frozen();
                }

                if (mm != null)
                {
                    //use if MoveablePlatform is mine not prefab
                    mm.Frize();
                }
                if (mc != null)
                {
                    //use if MoveablePlatform is mine not prefab
                    mc.Froze();
                }

                // Check if the object we hit has a rigidbody attached
                if (hit.rigidbody != null)
                {
                }
            }
            else
            {
                // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
    }