示例#1
0
    private void Update()
    {
        movement.Move(player.GetAxis2D("Move Horizontal", "Move Vertical"));
        //Debug.Log(player.GetAxis2D("Move Horizontal", "Move Vertical"));

        if (player.GetButton("Fire"))
        {
            FireButtonPressed();
        }
        if (player.GetButton("Fire2"))
        {
            Fire2ButtonPressed();
        }

        if (player.GetButton("Dash"))
        {
            DashButtonPressed();
        }

        if (mouseInput)
        {
            Vector3 v_diff = (MouseTargetLocation.position - transform.position);
            float   Rad    = Mathf.Atan2(v_diff.y, v_diff.x);
            float   angle  = Rad * Mathf.Rad2Deg;
            rotationEvent.Invoke(angle);
        }

        else
        {
            rotationEvent.Invoke(Quaternion.LookRotation(player.GetAxis2D("Rotate Horizontal", "Rotate Vertical")).eulerAngles.z);
            //    Debug.Log(Quaternion.LookRotation(player.GetAxis2D("Rotate Horizontal", "Rotate Vertical")).eulerAngles.z);
        }
    }
示例#2
0
        private async Task _loop()
        {
            while (_running)
            {
                try
                {
                    var result = await _mouseDevice.ReadAsync();

                    if (result.BytesRead >= 7)
                    {
                        if (result.Data[0] == (int)EventType.Translation)
                        {
                            CurrentTranslation = toVector3(result.Data) * TranslationScale;
                            TranslationEvent?.Invoke(this, CurrentTranslation);
                        }
                        else if (result.Data[0] == (int)EventType.Rotation)
                        {
                            CurrentRotation = toVector3(result.Data) * RotationScale;
                            RotationEvent?.Invoke(this, CurrentRotation);
                        }
                        else if (result.Data[0] == (int)EventType.Buttons)
                        {
                            CurrentButtons = ConvertByteArrayToBoolArray(result.Data.Skip(1).ToArray());
                            ButtonEvent?.Invoke(this, CurrentButtons);
                        }
                    }
                } catch (Exception ex) { }
            }
        }
        public IEnumerator MoveToPosition(Transform objectToMove, Vector3 position, Quaternion rotation)
        {
            //small hack to make sure quaterion.lerp actually does something
            if (rotation.eulerAngles.x == 0 && rotation.eulerAngles.y == 0 && rotation.eulerAngles.z == 0)
            {
                rotation = Quaternion.Euler(0.1f, 0.1f, 0.1f);
            }
            yield return(null);

            while (objectToMove.position.y > position.y + 0.1f)
            {
                if (Input.GetMouseButtonDown(0) || stopMovement)
                {
                    objectToMove.position = position;
                    objectToMove.rotation = rotation;
                    stopMovement          = false;
                    break;
                }
                objectToMove.position = Vector3.Lerp(objectToMove.position, position, lerpSpeed * Time.deltaTime);
                objectToMove.rotation = Quaternion.Lerp(objectToMove.rotation, rotation, lerpSpeed * Time.deltaTime);
                yield return(null);
            }

            OnMoved.Invoke();
            OnMovedRotation.Invoke(rotation);
        }
示例#4
0
        //=======================================================
        // Rotation Handlers
        //=======================================================
        public override void OnUpdateRotation(byte newFlags)
        {
            base.OnUpdateRotation(newFlags);
            Quaternion rotation = SegmentCustomRenderer.GetRotationQuaternion(newFlags);

            Forward = rotation * Vector3.forward;
            Left    = rotation * Vector3.left;
            Up      = rotation * Vector3.up;

            RotationEvent?.Invoke(this, rotation);
        }
示例#5
0
    private void Update()
    {
        if (!IsApplying)
        {
            return;
        }
        if (target.transform.rotation != _rotationPrevious)
        {
            RotationEvent?.Invoke(target.transform.localEulerAngles);
            onRotation?.Invoke();
        }

        _rotationPrevious = target.transform.rotation;
    }
示例#6
0
    void TrackRotation()
    {
        headTransform.LookAt(imageTargetTransform.position);
        rotationTracker.rotation = imageTargetTransform.rotation;
        Vector3 deltaRotation = rotationTracker.localEulerAngles;

        imageTargetTransform.LookAt(headTransform.position);

        if (Mathf.Abs(deltaRotation.x) < .5f)
        {
            deltaRotation.x = 0;
        }

        if (Mathf.Abs(deltaRotation.z) < .5f)
        {
            deltaRotation.z = 0;
        }

        if (Mathf.Abs(deltaRotation.y) > 0)
        {
            deltaRotation.y = deltaRotation.y - 180f;
        }
        else
        {
            deltaRotation.y = 180f + deltaRotation.y;
        }

        if (Mathf.Abs(deltaRotation.y) < .5f)
        {
            deltaRotation.y = 0;
        }

        if (OnRotationChange != null)
        {
            OnRotationChange.Invoke(deltaRotation);
        }
    }
 /**
  * raises RotationEvent
  */
 private void OnRotationEvent(float e)
 {
     RotationEvent?.Invoke(this, e);
 }