Beispiel #1
0
        // Update is called once per frame
        void Update()
        {
            Vector3 playerPosition = PlayerController.Instance.playerObject.transform.position;
            Vector3 centerPosition = VectorUtilities.GetFlatVector3AtHeight(EnvironmentController.Instance.levelCenter.position, playerPosition.y);

            SetCameraPosition(playerPosition, centerPosition);
            SetCameraRotation(playerPosition, centerPosition);
        }
Beispiel #2
0
        private void ConstrainDistanceFromLevelCenter()
        {
            Vector3 flatLevelCenterPosition = VectorUtilities.GetFlatVector3AtHeight(EnvironmentController.Instance.levelCenter.position, transform.position.y);
            Vector3 radiusVector            = transform.position - flatLevelCenterPosition;


            Vector3 translationVector = flatLevelCenterPosition + Vector3.Normalize(radiusVector) * EnvironmentController.Instance.distanceFromLevelCenter;

            transform.position = new Vector3(translationVector.x, transform.position.y, translationVector.z);
        }
Beispiel #3
0
        public void ClampSpeed()
        {
            float speedFactor = flyingSpeed / GetComponent <Rigidbody>().velocity.magnitude;

            if (speedFactor < 1)
            {
                Vector3 flatVelocity = VectorUtilities.GetFlatVector3(GetComponent <Rigidbody>().velocity);
                GetComponent <Rigidbody>().velocity = new Vector3(flatVelocity.x * speedFactor, GetComponent <Rigidbody>().velocity.y, flatVelocity.z * speedFactor);
            }
        }
Beispiel #4
0
        private void ExecuteMove(float xMove)
        {
            Vector3 rightWalkingDirection = righDirectionTransform.position - transform.position;

            rightAngle        = Vector3.Angle(GetComponent <Rigidbody>().velocity, rightWalkingDirection);
            acceleratingRight = rightAngle <90 && xMove> 0.1f;

            Vector3 leftWalkingDirection = leftDirectionTransform.position - transform.position;

            leftAngle        = Vector3.Angle(GetComponent <Rigidbody>().velocity, leftWalkingDirection);
            acceleratingLeft = leftAngle < 90 && xMove < -0.1f;
            bool accelerating = acceleratingLeft || acceleratingRight;

            if (!accelerating || GetPlayerHorizontalSpeed() < walkingSpeed)
            {
                float moveForce = xMove * Time.deltaTime * acceleration;
                GetComponent <Rigidbody>().AddForce(moveForce * VectorUtilities.PositionToTangentVector(transform.position, EnvironmentController.Instance.levelCenter.position));
            }
        }
Beispiel #5
0
        private void RotatePlayerVelocityAlongTangent()
        {
            Vector3 currentVelocity     = GetComponent <Rigidbody>().velocity;
            Vector3 currentFlatVelocity = VectorUtilities.GetFlatVector3(currentVelocity);
            Vector3 currentFlatTangent  = VectorUtilities.PositionToTangentVector(transform.position, EnvironmentController.Instance.levelCenter.position);

            float velocityOffsetAngle = Vector2.Angle(new Vector2(currentFlatTangent.x, currentFlatTangent.z), new Vector2(currentVelocity.x, currentVelocity.z));

            float flatVelocity = 0;

            if (velocityOffsetAngle <= 90)
            {
                flatVelocity = currentFlatVelocity.magnitude;
            }
            else
            {
                flatVelocity = -1 * currentFlatVelocity.magnitude;
            }
            GetComponent <Rigidbody>().velocity = new Vector3(currentFlatTangent.x * flatVelocity, currentVelocity.y, currentFlatTangent.z * flatVelocity);
            velocity = GetComponent <Rigidbody>().velocity;
        }
Beispiel #6
0
 private void SetTargetIndicator(Vector2 targetDirection)
 {
     targetVector = targetDirection;
     attackIndicatorRotationParent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, VectorUtilities.Vector2ToAngle(targetDirection)));
     attackIndicator.SetActive(true);
 }
Beispiel #7
0
 private void RotateTargetArrow(Vector2 inputDirection)
 {
     arrowRotationParent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, VectorUtilities.Vector2ToAngle(inputDirection)));
 }
Beispiel #8
0
        public void ShowTangets(Transform cube)
        {
            Vector3 tangentVector = VectorUtilities.PositionToTangentVector(cube.position, levelCenter.position);

            cube.rotation = Quaternion.LookRotation(tangentVector, Vector3.up);
        }
Beispiel #9
0
 private void SetPlayerRotation()
 {
     transform.rotation = Quaternion.LookRotation(VectorUtilities.PositionToTangentVector(transform.position, EnvironmentController.Instance.levelCenter.position), Vector3.up);
 }
Beispiel #10
0
        public float GetPlayerHorizontalSpeed()
        {
            Vector3 flatVelocity = VectorUtilities.GetFlatVector3(GetComponent <Rigidbody>().velocity);

            return(flatVelocity.magnitude);
        }