Beispiel #1
0
        protected virtual void FixedUpdate()
        {
            var currentPoint = (Vector2)transform.position;
            var vector       = targetPoint - currentPoint;

            if (vector.magnitude <= MinimumDistance)
            {
                ChangeTargetPoint();

                vector = targetPoint - currentPoint;
            }

            // Limit target speed
            if (vector.magnitude > MaximumSpeed)
            {
                vector = vector.normalized * MaximumSpeed;
            }

            // Acceleration
            if (body == null)
            {
                body = GetComponent <Rigidbody2D>();
            }

            var factor = D2dHelper.DampenFactor(Acceleration, Time.deltaTime);

            body.velocity = Vector2.Lerp(body.velocity, vector * SpeedBoost, factor);
        }
Beispiel #2
0
        protected virtual void Update()
        {
            var localPosition = transform.localPosition;
            var targetX       = (Input.mousePosition.x - Screen.width / 2) * MoveScale;
            var targetY       = (Input.mousePosition.y - Screen.height / 2) * MoveScale;
            var factor        = D2dHelper.DampenFactor(MoveSpeed, Time.deltaTime);

            localPosition.x = Mathf.Lerp(localPosition.x, targetX, factor);
            localPosition.y = Mathf.Lerp(localPosition.y, targetY, factor);

            transform.localPosition = localPosition;

            // Left click?
            if (Input.GetMouseButtonDown(0) == true)
            {
                var mainCamera = Camera.main;

                if (MuzzlePrefab != null)
                {
                    Instantiate(MuzzlePrefab, transform.position, Quaternion.identity);
                }

                if (BulletPrefab != null && mainCamera != null)
                {
                    var position = mainCamera.ScreenToWorldPoint(Input.mousePosition);

                    Instantiate(BulletPrefab, position, Quaternion.identity);
                }
            }
        }
Beispiel #3
0
        private static float Dampen(float current, float target, float dampening, float elapsed, float minStep = 0.0f)
        {
            var factor   = D2dHelper.DampenFactor(dampening, elapsed);
            var maxDelta = Mathf.Abs(target - current) * factor + minStep * elapsed;

            return(Mathf.MoveTowards(current, target, maxDelta));
        }
Beispiel #4
0
        protected virtual void Update()
        {
            var factor = D2dHelper.DampenFactor(Dampening, Time.deltaTime);

            currentThrottle = Mathf.Lerp(currentThrottle, Throttle, factor);

            transform.localScale = MaxScale * Random.Range(1.0f - Flicker, 1.0f + Flicker) * currentThrottle;
        }
Beispiel #5
0
        protected virtual void Update()
        {
            // Update flipping if the game is playing
            if (Application.isPlaying == true)
            {
                cooldown -= Time.deltaTime;

                // Flip?
                if (cooldown <= 0.0f)
                {
                    FrontShowing = !FrontShowing;

                    ResetCooldown();
                }
            }

            // Get target angle based on flip state
            var targetAngle = FrontShowing == true ? 0.0f : 180.0f;

            // Slowly rotate to the target angle if the game is playing
            if (Application.isPlaying == true)
            {
                var factor = D2dHelper.DampenFactor(FlipSpeed, Time.deltaTime);

                angle = Mathf.Lerp(angle, targetAngle, factor);
            }
            // Instantly rotate if it's not
            else
            {
                angle = targetAngle;
            }

            transform.localRotation = Quaternion.Euler(0.0f, angle, 0.0f);

            // Make the destructible indestructible if it's past 90 degrees
            if (Destructible != null)
            {
                Destructible.Indestructible = targetAngle >= 90.0f;
            }

            // Update movement
            if (Application.isPlaying == true)
            {
                MoveProgress += MoveSpeed * Time.deltaTime;
            }

            var moveDistance = (EndPosition - StartPosition).magnitude;

            if (moveDistance > 0.0f)
            {
                var progress01 = Mathf.PingPong(MoveProgress / moveDistance, 1.0f);

                transform.localPosition = Vector3.Lerp(StartPosition, EndPosition, Mathf.SmoothStep(0.0f, 1.0f, progress01));
            }
        }
Beispiel #6
0
        protected virtual void LateUpdate()
        {
            if (Application.isPlaying == true)
            {
                var factor = D2dHelper.DampenFactor(FlashDampening, Time.deltaTime, 0.1f);

                Flash = Mathf.Lerp(Flash, 0.0f, factor);
            }

            cachedCanvasGroup.alpha = Flash > 0.005f ? Flash : 0.0f;
        }
Beispiel #7
0
        protected virtual void Update()
        {
            var targetAngle = Input.GetAxisRaw("Horizontal") * SteerAngleMax;
            var factor      = D2dHelper.DampenFactor(SteerAngleDampening, Time.deltaTime);

            currentAngle = Mathf.Lerp(currentAngle, targetAngle, factor);

            for (var i = 0; i < SteerWheels.Length; i++)
            {
                SteerWheels[i].transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -currentAngle);
            }
        }
Beispiel #8
0
        protected virtual void LateUpdate()
        {
            var factor = D2dHelper.DampenFactor(ShakeDampening, Time.deltaTime, 0.1f);

            Shake = Mathf.Lerp(Shake, 0.0f, factor);

            var shakeStrength = Shake * ShakeScale;
            var shakeTime     = Time.time * ShakeSpeed;
            var localPosition = transform.localPosition;

            localPosition.x = Mathf.PerlinNoise(offsetX, shakeTime) * shakeStrength;
            localPosition.y = Mathf.PerlinNoise(offsetY, shakeTime) * shakeStrength;

            transform.localPosition = localPosition;
        }
Beispiel #9
0
        protected virtual void FixedUpdate()
        {
            if (Target != null)
            {
                // Get the main camera
                var mainCamera = Camera.main;

                // Begin dragging
                if (Input.GetKey(Requires) == true)
                {
                    var position = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera);
                    var factor   = D2dHelper.DampenFactor(Dampening, Time.fixedDeltaTime);

                    Target.velocity += (Vector2)(position - Target.transform.position) * factor;
                }
            }
        }