示例#1
0
    public void Update()
    {
        var     player         = getPlayerTransform();
        var     transform      = getCameraTransform();
        Vector3 playerPosition = player.position;

        Torus.GetPoint(playerPosition, out TorusPointInfo pInfo);
        Vector3 slope          = -pInfo.minorCenterUp;
        Vector3 playerUp       = -pInfo.minorCenterForward;
        Vector3 playerRight    = -pInfo.minorCenterRight;
        Vector3 targetPosition = playerPosition + slope * config.offset.z + playerUp * config.offset.y;

        if (Application.isPlaying)
        {
            transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, config.smoothTime);
        }
        else
        {
            transform.position = targetPosition;
        }

        var lookAtTarget = playerPosition + slope * config.lootAtOffset.z + playerUp * config.lootAtOffset.y;
        var lookAt       = (lookAtTarget - transform.position).normalized;
        var up           = Vector3.Cross(playerRight, lookAt);

        if (Application.isPlaying)
        {
            transform.rotation = QuaternionUtil.SmoothDamp(transform.rotation, Quaternion.LookRotation(lookAt, up), ref quaternionDeriv, config.smoothTime);
        }
        else
        {
            transform.rotation = Quaternion.LookRotation(lookAt, up);
        }
    }
示例#2
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            followTransform = null;
        }
        if (followTransform != null)
        {
            position = followTransform.position;
        }
        else
        {
            HandleInput();
        }

        position.x = Mathf.Clamp(position.x, center.x - panLimit.x, center.x + panLimit.x);
        position.z = Mathf.Clamp(position.z, center.z - panLimit.y, center.z + panLimit.y);
        zoom.y     = Mathf.Clamp(zoom.y, minZoom, maxZoom);
        zoom.z     = Mathf.Clamp(zoom.z, -maxZoom, -minZoom);

        transform.position = Vector3.SmoothDamp(transform.position, position, ref velocity, panRate);
        transform.rotation = QuaternionUtil.SmoothDamp(transform.rotation, rotation, ref deriv, rotateRate);

        cameraTransform.localPosition = Vector3.SmoothDamp(cameraTransform.localPosition, zoom, ref zoomVelocity, zoomRate);
    }
示例#3
0
    public void FixedUpdateState()
    {
        if (isFinishedRotating)
        {
            return;
        }

        // Calculate direction to target
        Vector3 targetRot = stateMachine.taskDestinationPosition - stateMachine.transform.position;

        targetRot.y = 0.0f;
        targetRot.Normalize();

        // SmoothDamp towards to target rotation
        stateMachine.transform.rotation = QuaternionUtil.SmoothDamp(stateMachine.transform.rotation, Quaternion.LookRotation(targetRot), ref angularVelocity, stateMachine.rotationSpeed);

        // Calculate the angle between target position and customer forward vector
        float fromToDelta = Vector3.Angle(stateMachine.transform.forward, targetRot);

        Debug.DrawRay(stateMachine.transform.position, targetRot * 5.0f, Color.green);
        Debug.DrawRay(stateMachine.transform.position, stateMachine.transform.forward * 5.0f, Color.red);

        // Stop rotation if angle between target and forward vector is lower than margin of error
        if (fromToDelta <= marginOfErrorAmount)
        {
            isFinishedRotating = true;
            Debug.Log("Customer is now looking at the target!", stateMachine.gameObject);
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        //if (!target2.gameObject.activeInHierarchy) {
        Vector3 desiredPosition = target.position + target.forward * offset;

        transform.position = Vector3.SmoothDamp(transform.position, desiredPosition, ref velocity, smoothTimePos);
        Quaternion desiredRotation = target.rotation;

        transform.rotation = QuaternionUtil.SmoothDamp(transform.rotation, desiredRotation, ref deriv, smoothTimeRot);
        //} else {
        //this.gameObject.SetActive(false);
        //}
    }
示例#5
0
    void LateUpdate()
    {
        if (desiredPose != null)
        {
            transform.position = Vector3.SmoothDamp(transform.position, desiredPose.position, ref currentPositionCorrectionVelocity, positionSmoothTime, positionMaxSpeed, Time.deltaTime);

            var targForward = desiredPose.forward;
            //var targForward = (target.position - this.transform.position).normalized;

            transform.rotation = QuaternionUtil.SmoothDamp(transform.rotation,
                                                           Quaternion.LookRotation(targForward, Vector3.up), ref quaternionDeriv, rotationSmoothTime);
        }
    }
    /// <summary>
    /// Rotates subject towards the target using SmoothDamp
    /// </summary>
    /// <param name="transformToTurn">Subject to turn.</param>
    /// <param name="target">Target to turn subject towards.</param>
    /// <param name="currentVelocity">The current velocity, this value is modified by the function every time you call it.</param>
    /// <param name="smoothTime">Approximately the time it will take to reach the target. A smaller value will reach the target faster.</param>
    /// <returns>The delta angle between the direction the subject is facing to target position.</returns>
    public static float RotateTowardsTargetSmoothDamp(Transform transformToTurn, Vector3 target, ref Quaternion currentVelocity, float smoothTime)
    {
        // Calculate direction to target
        Vector3 targetRot = target - transformToTurn.position;

        targetRot.y = 0.0f;
        targetRot.Normalize();

        // SmoothDamp towards to target rotation
        transformToTurn.rotation =
            QuaternionUtil.SmoothDamp(
                transformToTurn.rotation,
                Quaternion.LookRotation(targetRot),
                ref currentVelocity,
                smoothTime
                );

        // Debug visuals
        Debug.DrawRay(transformToTurn.position, targetRot * 5.0f, Color.green);
        Debug.DrawRay(transformToTurn.position, transformToTurn.forward * 5.0f, Color.red);

        return(Vector3.Angle(transformToTurn.forward, targetRot));
    }