Exemplo n.º 1
0
        private void LateUpdate()
        {
            //Must be the local player to animate through here
            if (!isLocalPlayer)
            {
                return;
            }

            foreach (SimpleBodyPartLookAt part in LookAt)
            {
                part.MoveTarget();

                Vector3 forward = transform.TransformDirection(Vector3.forward).normalized;
                Vector3 toOther = (part.target.position - transform.position).normalized;

                Vector3    targetLookAt   = part.target.position - part.transform.position;
                Quaternion targetRotation = Quaternion.FromToRotation(forward, targetLookAt.normalized);
                targetRotation = Quaternion.RotateTowards(part.currentRot, targetRotation, Time.deltaTime * part.rotationSpeed * Mathf.Rad2Deg);

                float targetAngle = Mathf.Abs(Quaternion.Angle(Quaternion.identity, targetRotation));
                if (targetAngle > part.minRotationLimit && targetAngle < part.maxRotationLimit)
                {
                    part.currentRot = targetRotation;
                }
                part.transform.localRotation = part.currentRot;
            }

            // TODO: Might eventually want more animation options. E.g. when in 0-gravity and 'clambering' via a surface
            //characterAnimator.SetBool("Floating", false); // Note: Player can be floating and still move
        }
Exemplo n.º 2
0
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player") && other.GetType() != typeof(BoxCollider2D))
        {
            //return the players gravity to normal
            rbPlayer.gravityScale = 0.1f;

            //Declares an upright rotation
            Quaternion target = Quaternion.Euler(0, 0, 0);

            //Rotates the player to upright
            while (Quaternion.Angle(player.transform.rotation, target) > 0)
            {
                player.transform.rotation = Quaternion.Slerp(player.transform.rotation, target, Time.deltaTime * smooth);
            }


            //Sets that the player has left the planet radius
            playerController.Attracted = false;

            //Gives the player a boost as they leave the planet radius
            var outDir = GetDirection(planetBody.transform.position, player.transform.position) * 5;
            rbPlayer.AddForce(outDir, ForceMode2D.Force);

            virtualCamera.Priority = 10;
        }
    }
        private void Update()
        {
            Vector3 toTarget           = TargetPoint - transform.position;
            float   distanceFromTarget = toTarget.magnitude;

            if (distanceFromTarget < distanceTolerance)
            {
                CurrentSpeed       = 0.0f;
                transform.position = TargetPoint;
                return;
            }

            Quaternion targetRotation = Quaternion.LookRotation(toTarget.normalized);
            float      angleRemaining = Quaternion.Angle(transform.rotation, targetRotation);

            if (angleRemaining > rotationTolerance)
            {
                if (CurrentRotationSpeed < maxRotationSpeedInDegrees)
                {
                    CurrentRotationSpeed += rotationAccelerationInDegrees * Time.deltaTime;
                }
                Mathf.Min(CurrentRotationSpeed, maxRotationSpeedInDegrees);

                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation,
                                                              CurrentRotationSpeed * Time.deltaTime);
                return;
            }

            if (distanceFromTarget <= decelerationDistance)
            {
                if (!isDecelerating)
                {
                    isDecelerating = true;
                    deceleration   = 0.5f * CurrentSpeed * CurrentSpeed / decelerationDistance;
                }

                CurrentSpeed -= deceleration * Time.deltaTime;
                if (CurrentSpeed < speedTolerance)
                {
                    CurrentSpeed       = 0;
                    transform.position = TargetPoint;
                }
            }
            else if (CurrentSpeed < maxSpeed)
            {
                CurrentSpeed += acceleration * Time.deltaTime;
            }
            CurrentSpeed = Mathf.Min(CurrentSpeed, maxSpeed);

            transform.position = Vector3.MoveTowards(transform.position, TargetPoint, CurrentSpeed * Time.deltaTime);
        }