Beispiel #1
0
    void Update()
    {
        if (characterController.getIsJumping())
        {
            if (characterController.getIsGoingUp())
            {
                bpAnimator.SetBool("isGoingUp", true);
            }
            else
            {
                bpAnimator.SetBool("isGoingUp", false);
            }
        }
        else
        {
            FinishJump();
            if (isSpaceJumping)
            {
                FinishSpaceJump();
            }
        }

        bool canBreatheInActualPlanet = GameManager.playerSpaceBody.canBreatheInActualPlanet();

        if (body.getUsesSpaceGravity() || (!canBreatheInActualPlanet))
        {
            if (!body.getIsOutsideAthmosphere() && canBreatheInActualPlanet)
            {
                timeHasBeenInSpace = 0f;
            }
            float ratio = 1f - (timeHasBeenInSpace / timeToDieInSpace);
            GUIManager.setPercentageOfBreathing(ratio);
        }


        if ((body.getIsOutsideAthmosphere() || !canBreatheInActualPlanet) && canDrownInSpace)
        {
            //breathingBubble.SetActive(true);
            GUIManager.activateSpaceJumpGUI();
            //rigidbody.velocity = rigidbody.velocity.normalized * (Constants.GRAVITY_FORCE_OF_PLANETS/1.5f);

            if (!GameManager.isGameEnded)
            {
                if (timeHasBeenInSpace >= timeToDieInSpace)
                {
                    //breathingBubble.transform.localScale = new Vector3(0f,0f,0f);
                    timeHasNotBeenBreathing += Time.deltaTime;
                    if (timeHasNotBeenBreathing >= timeBetweenDamageWhenNotBreathing)
                    {
                        dieInSpace();
                    }
                }
                else
                {
                    timeHasBeenInSpace += Time.deltaTime;
                    float ratio = 1f - (timeHasBeenInSpace / timeToDieInSpace);
                    //float newScale = ((maximumBreathingBubbleScale - minimumBreathingBubbleScale) * ratio)+minimumBreathingBubbleScale;
                    //breathingBubble.transform.localScale = new Vector3(newScale,newScale,newScale);
                }
            }
        }
        else
        {
            if (!GameManager.isGameEnded && canBreatheInActualPlanet)
            {
                timeHasBeenInSpace = 0f;
                //breathingBubble.SetActive(false);
            }
        }

        if (!isShowingLineJump)
        {
            HideArrow();
        }
        else
        {
            ActArrow();
        }
    }
Beispiel #2
0
    private bool spaceAttract(Transform objectToAttract, out float distance, bool applyForce, bool hasToChangeFacing, float gravityMultiplyier)
    {
        //Only attract the body to the planet if it is close enough.
        distance = Vector3.Distance(transform.position, objectToAttract.position);
        SpaceGravityBody body           = objectToAttract.GetComponent <SpaceGravityBody> ();
        float            forceMagnitude = body.GetComponent <Rigidbody>().velocity.magnitude;

        distance = distance - sphereRadius;

        if (distance <= gravityDistance)
        {
            Vector3 targetDir = (objectToAttract.position - transform.position);
            targetDir = new Vector3(targetDir.x, targetDir.y, 0f).normalized;

            Vector3 objectUp = objectToAttract.up;

            if (hasToChangeFacing)
            {
                objectToAttract.rotation = Quaternion.FromToRotation(objectUp, targetDir) * objectToAttract.rotation;
            }
            float forceToAdd = -Constants.GRAVITY_FORCE_OF_PLANETS * Time.deltaTime;

            bool hasToAddForce = true;

            float ratioDistance = distance / gravityDistance;
            if (body.getUsesSpaceGravity())
            {
                bool isOrbiting = body.getIsOrbitingAroundPlanet();
                if (!isOrbiting)
                {
                    float angle = Vector3.Angle(body.GetComponent <Rigidbody>().velocity, targetDir);
                    angle = Mathf.Abs(angle);
                    if (angle >= Constants.ANGLE_CAN_ENTER_ORBIT_START && angle <= Constants.ANGLE_CAN_ENTER_ORBIT_END)
                    {
                        if (ratioDistance >= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_START && ratioDistance <= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_END)
                        {
                            GameManager.mainCamera.GetComponent <CameraFollowingPlayer> ().followObjective(gameObject);
                            isOrbiting = true;
                            body.setIsOrbitingAroundPlanet(true);
                        }
                    }
                }

                if (ratioDistance <= Constants.PERCENTAGE_ATHMOSPHERE_CAN_ENTER_ORBIT_START)
                {
                    if (isOrbiting)
                    {
                        GameManager.mainCamera.GetComponent <CameraFollowingPlayer> ().unfollowObjective();
                    }
                    isOrbiting = false;
                    body.setIsOrbitingAroundPlanet(false);
                }
                if (isOrbiting && !body.getIsGettingOutOfOrbit())
                {
                    hasToAddForce = false;
                    //Meeec, no funciona be, sempre va a la dreta
                    //bool goesRight = Vector3.Angle(targetDir,-body.rigidbody.velocity) < Vector3.Angle(targetDir,body.rigidbody.velocity);
                    bool  goesRight = GameManager.player.GetComponent <PlayerController>().getIsLookingRight();
                    float angle2    = Util.getAngleFromVectorAToB(body.GetComponent <Rigidbody>().velocity, transform.position - body.transform.position);
                    goesRight = angle2 < 0f;


                    if (goesRight)
                    {
                        forceMagnitude *= -1;
                    }
                    else
                    {
                        targetDir *= -1f;
                    }
                    float forceRatio = Mathf.Cos(Mathf.Deg2Rad * Vector3.Angle(body.GetComponent <Rigidbody>().velocity, targetDir));

                    Vector3 forwardDirection = body.GetComponent <Rigidbody>().transform.forward.normalized;

                    if (!GameManager.player.GetComponent <PlayerController>().getIsLookingRight())
                    {
                        forwardDirection *= -1f;
                    }
                    body.GetComponent <Rigidbody>().velocity = ((forwardDirection) + (((targetDir.normalized) * Mathf.Abs(forceRatio)))).normalized * forceMagnitude;
                    if (body.getIsFallingIntoPlanet())
                    {
                        body.GetComponent <Rigidbody>().velocity -= objectUp * Constants.AMMOUNT_OF_DOWN_SPEED_ON_LANDING;
                    }
                    objectToAttract.parent = transform;
                }


                float ratio = 1f - (distance / gravityDistance);
                forceToAdd *= Constants.GRAVITY_MULTIPLYIER_ON_SPACE_JUMPS * ratio;
            }
            if (body.getIsGettingOutOfOrbit())
            {
                hasToAddForce = false;
            }
            if (hasToAddForce && applyForce)
            {
                objectToAttract.GetComponent <Rigidbody>().AddForce(gravityMultiplyier * targetDir * forceToAdd, ForceMode.VelocityChange);
            }
            body.GetComponent <Rigidbody>().velocity = body.GetComponent <Rigidbody>().velocity.normalized *Mathf.Abs(forceMagnitude);
            //We only put the body in the hierarchy if it has touched a planet after doing "Space travel".
            if (!body.getUsesSpaceGravity())
            {
                objectToAttract.parent = transform;
            }

            return(true);
        }
        return(false);
    }