Exemplo n.º 1
0
    public void UpdateFlare(Sprite sprite, Vector3 targetScale, float flicker, float dampening)
    {
        // Get or add SpriteRenderer?
        if (spriteRenderer == null)
        {
            spriteRenderer = SgtHelper.GetOrAddComponent <SpriteRenderer>(gameObject);

            spriteRenderer.sharedMaterial = FlareMaterial;
        }

        // Assign the default material?
        if (spriteRenderer.sharedMaterial == null)
        {
            SgtHelper.BeginStealthSet(spriteRenderer);
            {
                spriteRenderer.sharedMaterial = FlareMaterial;
            }
            SgtHelper.EndStealthSet();
        }

        // Assign the current sprite?
        if (spriteRenderer.sprite != sprite)
        {
            spriteRenderer.sprite = sprite;
        }

        // Transition scale
        CurrentScale = SgtHelper.Dampen3(CurrentScale, targetScale, dampening, Time.deltaTime, 0.1f);
        finalScale   = CurrentScale * (1.0f - flicker);
    }
Exemplo n.º 2
0
    protected virtual void Update()
    {
        var sensitivity = Sensitivity;

        var camera = Camera;

        if (camera == null)
        {
            camera = Camera.main;
        }

        if (camera != null && camera.orthographic == false)
        {
            sensitivity *= camera.fieldOfView / 60.0f;
        }

        if (Require == KeyCode.None || Input.GetKey(Require) == true)
        {
            Remaining.x -= Input.GetAxisRaw("Mouse Y") * sensitivity;
            Remaining.y += Input.GetAxisRaw("Mouse X") * sensitivity;
        }

        var dampened = SgtHelper.Dampen3(Remaining, Vector3.zero, Dampening, Time.deltaTime, 0.1f);
        var delta    = Remaining - dampened;

        Remaining = dampened;

        transform.Rotate(delta);
    }
Exemplo n.º 3
0
    protected virtual void Update()
    {
        if (Require == KeyCode.None || Input.GetKey(Require) == true)
        {
            targetPosition += transform.forward * Input.GetAxisRaw("Vertical") * Sensitivity * Time.deltaTime;

            targetPosition += transform.right * Input.GetAxisRaw("Horizontal") * Sensitivity * Time.deltaTime;
        }

        var currentPosition = SgtHelper.Dampen3(transform.position, targetPosition, Dampening, Time.deltaTime, 0.1f);

        SgtHelper.SetPosition(transform, currentPosition);
    }
Exemplo n.º 4
0
    protected virtual void Update()
    {
        if (targetAxis == Vector3.zero || Vector3.Distance(targetAxis, Axis) < 0.1f)
        {
            targetAxis.x = Random.Range(-1.0f, 1.0f);
            targetAxis.y = Random.Range(-1.0f, 1.0f);
            targetAxis.z = Random.Range(-1.0f, 1.0f);
            targetAxis   = targetAxis.normalized;
        }

        Axis = SgtHelper.Dampen3(Axis, targetAxis, Dampening, Time.deltaTime, 0.1f);

        transform.Rotate(Axis.normalized, DegreesPerSecond * Time.deltaTime);
    }
Exemplo n.º 5
0
    // This static method will move the transform down to the surface of the terrain
    public static void SnapTransformPosition(SgtTerrain terrain, Transform transform, float offset = 0.0f, float dampening = 0.0f)
    {
        if (terrain != null && transform != null)
        {
            var oldPosition = transform.position;
            var newPosition = terrain.GetWorldPoint(oldPosition, offset);

            if (oldPosition != newPosition)
            {
                if (dampening > 0.0f)
                {
                    transform.position = SgtHelper.Dampen3(transform.position, newPosition, dampening, Time.deltaTime);
                }
                else
                {
                    transform.position = newPosition;
                }
            }
        }
    }
Exemplo n.º 6
0
    protected virtual void Update()
    {
        var maxSpeed = CalculateMaxSpeed();

        if (Require == KeyCode.None || Input.GetKey(Require) == true)
        {
            offset += transform.forward * Input.GetAxisRaw("Vertical") * maxSpeed * Time.deltaTime;

            offset += transform.right * Input.GetAxisRaw("Horizontal") * maxSpeed * Time.deltaTime;
        }

        // Dampen current position to target position
        var oldPosition    = transform.position;
        var targetPosition = transform.position + offset;
        var newPosition    = SgtHelper.Dampen3(oldPosition, targetPosition, Dampening, Time.deltaTime, 0.1f);

        transform.position = newPosition;

        // Reduce offset by dampen amount
        offset -= newPosition - oldPosition;

        // Make sure the position isn't inside a terrain
        RepelPositions();
    }