예제 #1
0
        public void Move(InputAction.CallbackContext ctx)
        {
            _moveInput = ctx.ReadValue <Vector2>();

            var roll  = -_moveInput.x;
            var pitch = -_moveInput.y;

            _aircraft.SetAngles(roll, pitch);
        }
        private void Update()
        {
            if (Vector3.Distance(transform.position, NextPoint) < TargetDistanceToPoint)
            {
                SetNextPoint();
            }

            var dot            = Vector3.Dot(_aircraft.GetDirection(), TargetDirection());
            var directionAngle = Vector3.SignedAngle(_aircraft.GetDirection(), TargetDirection(), Vector3.up);

            Debug.Log("distance: " + Vector3.Distance(transform.position, NextPoint) + ", dot: " + dot +
                      ", directionAngle: " + directionAngle + ", angles: " + _aircraft.transform.rotation.eulerAngles);



            if (dot < 0.90f)
            {
                _isTurning = true;
            }
            if (dot > 0.95f)
            {
                _isTurning = false;
            }

            var zAngle = _aircraft.transform.rotation.eulerAngles.z;

            if (zAngle > 180)
            {
                zAngle -= 360;
            }

            if (_isTurning)
            {
                if (zAngle < 85)
                {
                    _aircraft.SetAngles(1, 0);
                }
                else if (zAngle > 95)
                {
                    _aircraft.SetAngles(-1, 0);
                }
                else
                {
                    if (directionAngle > 0)
                    {
                        _aircraft.SetAngles(0, 0.5f);
                    }
                    else
                    {
                        _aircraft.SetAngles(0, -0.5f);
                    }
                }
            }
            else
            {
                if (zAngle > 5)
                {
                    _aircraft.SetAngles(-1, 0);
                }
                else if (zAngle < -5)
                {
                    _aircraft.SetAngles(1, 0);
                }
                else
                {
                    _aircraft.SetAngles(0, 0);
                }
            }
        }