Esempio n. 1
0
        public void Detect(ref MovementInput input)
        {
            int targetCount = Physics2D.OverlapCircleNonAlloc(detectionTransform.position, detectionRange, targetArray, layerMask);

            HasDetectedTarget = targetCount > 0;

            if (!HasDetectedTarget && targetArray.Length > 0)
            {
                targetArray      = new Collider2D[1];
                focusedTarget    = null;
                target           = null;
                input.MoveVector = Vector2.zero;
                weapon.Stop();
                return;
            }

            target = targetArray[0];

            focusedTarget = target.transform;

            input.MoveVector = focusedTarget.position - detectionTransform.position;
            input.MoveVector.Normalize();

            if (!weapon.IsFiring)
            {
                weapon.Use(focusedTarget);
            }
        }
Esempio n. 2
0
 private void OnEnable()
 {
     shotlock = GetComponentInParent <ShotLock>();
     movement = FindObjectOfType <MovementInput>();
     shotlock.ActivateShotLock();
     movement.enabled = false;
 }
Esempio n. 3
0
        public ControllerCursor(Node parent, string name, MovementInput input)
            : base(parent, name)
        {
            Input = input;

            MakeDefault();
        }
Esempio n. 4
0
    // Missing value checks
    void Awake()
    {
        maxHealth = (float)health;

        if (!debugInitWarnings)
        {
            return;
        }
        if (alliance == "")
        {
            Debug.LogWarning("Set alliance.", this);
        }
        if (health == 0)
        {
            Debug.LogWarning("Set hp", this);
        }
        if (unitCollision == null)
        {
            Debug.LogWarning("Set collider manualy", this);
            unitCollision = GetComponent <Collider2D>();
        }
        if (input == null)
        {
            Debug.LogWarning("Set ai manualy", this);
            input = GetComponent <AiInput>();
        }
    }
Esempio n. 5
0
 private void Start()
 {
     weapon.onHit.AddListener((target) => HitTarget(target));
     movement         = GetComponent <MovementInput>();
     anim             = GetComponent <Animator>();
     camImpulseSource = Camera.main.GetComponent <CinemachineImpulseSource>();
 }
Esempio n. 6
0
    /// <summary>
    /// Updates the current movement state and updates player movement to current state.
    /// </summary>
    private void UpdateInput()
    {
        _movementInput = GetMovementState();

        switch (_movementInput)
        {
        case MovementInput.Idle:
            break;

        case MovementInput.WalkLeft:
            _rigidbody.AddForce(Vector2.left * moveSpeed);
            break;

        case MovementInput.WalkRight:
            _rigidbody.AddForce(Vector2.right * moveSpeed);
            break;

        case MovementInput.RunLeft:
            _rigidbody.AddForce(Vector2.left * (moveSpeed * runSpeedMultiplier));
            break;

        case MovementInput.RunRight:
            _rigidbody.AddForce(Vector2.right * (moveSpeed * runSpeedMultiplier));
            break;

        case MovementInput.Jump:
            _rigidbody.AddForce(Vector2.up * jumpForce);
            break;
        }
    }
Esempio n. 7
0
    // Start is called before the first frame update
    void Start()
    {
        characterInput = GameObject.FindWithTag("Player").GetComponent <MovementInput>();
        playerAnchor   = GameObject.FindWithTag("PlayerCameraAnchor").GetComponent <Transform>();

        Parent = this.transform.parent;
    }
    void RetrieveInput(MovementInput horizontalInput)
    {
        if (movementController.enabled)
        {
            if (horizontalInput.touchPosition == 0.0f)
            {
                if (animationFloat < 0.0f)
                {
                    animationFloat += 0.05f;
                }
                else if (animationFloat > 0.0f)
                {
                    animationFloat -= 0.05f;
                }
            }
            else if (horizontalInput.touchPosition > 0 && animationFloat < 1f)
            {
                animationFloat += 0.05f;
            }
            else if (horizontalInput.touchPosition < 0 && animationFloat > -1f)
            {
                animationFloat -= 0.05f;
            }

            movementController.Turn(horizontalInput.touchPosition);
            animator.SetFloat("TurnAmount", animationFloat);
        }
    }
Esempio n. 9
0
        public ControllerCursor(Node parent, string name, MovementInput input)
            : base(parent, name)
        {
            Input = input;

            MakeDefault();
        }
Esempio n. 10
0
        static Task ListenForInput()
        {
            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey(intercept: true);
                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.W:
                    case ConsoleKey.UpArrow:
                        MovementInput?.Invoke(1f);
                        break;

                    case ConsoleKey.S:
                    case ConsoleKey.DownArrow:
                        MovementInput?.Invoke(-1f);
                        break;

                    case ConsoleKey.Enter:
                        EnterPressed?.Invoke();
                        break;
                    }
                }
            }
        }
Esempio n. 11
0
 void Awake()
 {
     Movement = new MovementInput(PlayerSpecificAxisName("Horizontal"), PlayerSpecificAxisName("Vertical"));
     Jump     = new GenericInput(PlayerSpecificAxisName("Jump"));
     Action_1 = new GenericInput(PlayerSpecificAxisName("Action_1")); //Left Action
     Action_2 = new GenericInput(PlayerSpecificAxisName("Action_2")); //Top Action
     Action_3 = new GenericInput(PlayerSpecificAxisName("Action_3")); //Right Action
 }
Esempio n. 12
0
    void Start()
    {
        anim = GetComponent <Animator>();

        player      = GameObject.FindGameObjectWithTag("Player");
        moveInpt    = player.GetComponent <MovementInput>();
        audioPlayer = GameObject.FindGameObjectWithTag("AudioSources").GetComponent <AudioPlayer>();
    }
Esempio n. 13
0
        private void UpdateMoveAnimation()
        {
            var positionChange = MovementInput.GetPositionChangeByDirection(_moveDirection);

            _animator.SetFloat("moveX", positionChange.x);
            _animator.SetFloat("moveY", positionChange.y);
            _animator.SetBool("moving", _moving);
        }
        public void ProcessMovementCommand(MovementInput movInput)
        {
            var moveDir = transform.rotation * movInput.MovementDir;
            //todo: Movement speed
            //todo: jump
            var newRot = BuildRotationFromInput(movInput);

            pitchTransform.localRotation = Quaternion.Euler(newRot.eulerAngles.x, 0, 0);
        }
Esempio n. 15
0
    // Start is called before the first frame update
    void Start()
    {
        Cursor.visible = false;

        input                = GetComponent <MovementInput>();
        anim                 = GetComponent <Animator>();
        originalFOV          = thirdPersonCamera.m_Lens.FieldOfView;
        originalCameraOffset = thirdPersonCamera.GetRig(1).GetCinemachineComponent <CinemachineComposer>().m_TrackedObjectOffset;
    }
Esempio n. 16
0
    // Start is called before the first frame update
    void Start()
    {
        charMovement = FindObjectOfType <MovementInput>();

        PikminSpawner[] spawners = FindObjectsOfType(typeof(PikminSpawner)) as PikminSpawner[];
        foreach (PikminSpawner spawner in spawners)
        {
            spawner.SpawnPikmin(pikminPrefab, ref allPikmin);
        }
    }
Esempio n. 17
0
 private void OnEnable()
 {
     MovementInput = GetComponent <MovementInput>();
     if (!MovementInput)
     {
         MovementInput = GetComponentInChildren <MovementInput>();
     }
     SkillController  = PlayerInControl.GetComponent <SkillController>();
     EntityController = PlayerInControl.GetComponent <EntityController>();
 }
Esempio n. 18
0
        private void InitInput()
        {
#if UNITY_EDITOR
            _input = new KeyboarInput();
#else
            _input = new JoystickInput();
#endif
            _input.OnInputBegin += () => {};
            _input.OnInputEnded += () => {};
        }
Esempio n. 19
0
 //Default settings
 public void MakeDefault()
 {
     SelectKey   = new GamepadInput(this, "SelectKey", Buttons.A, PlayerIndex.One);
     AnalogStick = new GamePadAnalog(this, "AnalogStick", Sticks.Right, PlayerIndex.One);
     UpKey       = new GamepadInput(this, "UpKey", Buttons.DPadUp, PlayerIndex.One);
     DownKey     = new GamepadInput(this, "DownKey", Buttons.DPadDown, PlayerIndex.One);
     LeftKey     = new GamepadInput(this, "LeftKey", Buttons.DPadLeft, PlayerIndex.One);
     RightKey    = new GamepadInput(this, "RightKey", Buttons.DPadRight, PlayerIndex.One);
     Input       = MovementInput.Analog;
 }
Esempio n. 20
0
 private void Start()
 {
     playerAnimator   = GetComponent <Animator>();
     playerMovement   = GetComponent <MovementInput>();
     playerController = GetComponent <CharacterController>();
     brain            = Camera.main.GetComponent <CinemachineBrain>();
     playerZScale     = transform.GetChild(0).localScale.z;
     frameRenderer    = frameQuad.GetComponent <Renderer>();
     impulseSource    = Camera.main.GetComponent <CinemachineImpulseSource>();
 }
        protected override void OnUpdate()
        {
            var left     = false;
            var right    = false;
            var forward  = false;
            var backward = false;

#if UNITY_DOTSPLAYER
            var Input = World.GetExistingSystem <InputSystem>();
#endif

            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            {
                forward = true;
            }
            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            {
                backward = true;
            }

            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
            {
                left = true;
            }
            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
            {
                right = true;
            }

            MovementInput input = default;

            if (left && right)
            {
                input.horizontalAxis = 0f;
            }
            else if (left)
            {
                input.horizontalAxis = -1f;
            }
            else if (right)
            {
                input.horizontalAxis = 1f;
            }

            if (forward)
            {
                input.verticalAxis = 1f;
            }
            else if (backward)
            {
                input.verticalAxis = -1f;
            }

            Entities.ForEach((ref MovementInput inputRef) => { inputRef = input; }).Schedule();
        }
Esempio n. 22
0
    /// <summary>
    /// _moveVector만큼 Rigidbody를 이동시킵니다( FixedUpdate 권장...).
    /// </summary>
    /// <param name="_moveType">이동 타입입니다.</param>
    /// <param name="_moveVector">방향 * 원하는 속도의 값입니다. 타입 VDP의 경우, 목적지 위치로 사용됩니다.</param>
    public void SetMovement(eMovementType _moveType, Vector2 _moveVector)
    {
        currentMovementType = _moveType;

        MovementInput movementInput = new MovementInput(_moveType, _moveVector);

        //if (haveParents) // 부모가 있다면
        //{
        //    _moveVector = parentsObject.myRigidbody.velocity + _moveVector; //무브 벡터에 벨로시티 더하기
        //}



        switch (_moveType)
        {
        case eMovementType.SetVelocity:
            if (myRigidbody.velocity != _moveVector)
            {
                myRigidbody.velocity = _moveVector;
            }
            break;

        case eMovementType.AddVelocity:
            myRigidbody.velocity += _moveVector;
            break;

        case eMovementType.SetVelocityDesiredPosition:

            myRigidbody.velocity = CalcDesiredVelocity(_moveVector);
            break;
            //case eMovementType.AddForce:

            //    myRigidbody.AddForce(_moveVector, ForceMode2D.Impulse);
            //    break;


            #region 사용하지 않음
            //case eMovementType.AddVelocity:

            //    myRigidbody.velocity += _moveVector;
            //    break;

            //case eMovementType.MovePosition:

            //    myRigidbody.MovePosition(_moveVector);
            //    break;
            #endregion
        default:
            break;
        }
        moveVector = _moveVector;
        //  UpdateParentsFollowMovement();
        CalcLastVelocity();
    }
Esempio n. 23
0
        private void Awake()
        {
            characterController = GetComponent <CharacterController>();
            movementInput       = GetComponent <MovementInput>();

            //Инициализация
            characterController.enabled = false;
            movementInput.enabled       = false;
            meshRenderer.enabled        = false;
            meshRenderer.sharedMaterial.SetFloat("_strenght", -1f);
        }
Esempio n. 24
0
    void Start()
    {
        Cursor.visible = false;

        animator     = GetComponent <Animator>();
        input        = GetComponent <MovementInput>();
        weaponRb     = weapon.GetComponent <Rigidbody>();
        weaponScript = weapon.GetComponent <WeaponAnimate>();
        origLocPos   = weapon.localPosition;
        origLocRot   = weapon.localEulerAngles;
    }
 void Start()
 {
     Cursor.visible       = false;
     postVolume           = Camera.main.GetComponentInChildren <PostProcessVolume>();
     postProfile          = postVolume.profile;
     ui                   = GetComponent <InterfaceAnimator>();
     anim                 = this.GetComponent <Animator>();
     input                = GetComponent <MovementInput>();
     originalFOV          = thirdPersonCamera.m_Lens.FieldOfView;
     originalCameraOffset = thirdPersonCamera.GetRig(1).GetCinemachineComponent <CinemachineComposer>().m_TrackedObjectOffset;
 }
Esempio n. 26
0
 private void StrafeBike(MovementInput e)
 {
     if (e.touchPosition == 0f)
     {
         AkSoundEngine.SetRTPCValue("Strafing", 0f);
     }
     else
     {
         AkSoundEngine.SetRTPCValue("Strafing", 1f);
     }
 }
Esempio n. 27
0
        public void Update(float frameTime, float heightDifference, MovementInput input)
        {
            _velocity.Update(frameTime, input);
            _lookDirection.Update(frameTime, input);

            if (input.Jump && heightDifference < 0.1f)
            {
                _verticalVelocity = 1.0f;
            }

            if (_verticalVelocity > -10.0f)
            {
                _verticalVelocity -= 0.05f;
            }

            Rotation.X += _lookDirection.Down;
            Rotation.X  = Rotation.X.Clamp(-90, 90);

            Rotation.Y += _lookDirection.Right;
            Rotation.Y  = Rotation.Y.RotationLock();

            var radians  = Rotation.Y * Constants.RadiansPerDegree;
            var sideways = (Rotation.Y + 90) * Constants.RadiansPerDegree;

            var forwardX = (float)Math.Sin(radians) * _velocity.NetForward;
            var forwardZ = (float)Math.Cos(radians) * _velocity.NetForward;

            var sidewaysX = (float)Math.Sin(sideways) * _velocity.NetRightward;
            var sidewaysZ = (float)Math.Cos(sideways) * _velocity.NetRightward;

            var netMovement = new Vector2(forwardX + sidewaysX, forwardZ + sidewaysZ);

            var maxVelocity = Constants.MaxVelocity;

            if (input.Sprint)
            {
                maxVelocity *= 3;
            }

            if (netMovement.Length() > maxVelocity)
            {
                netMovement = Vector2.Normalize(netMovement);
                netMovement = Vector2.Multiply(netMovement, maxVelocity);
            }

            Position.X += netMovement.X;
            Position.Y += _verticalVelocity;
            Position.Z += netMovement.Y;

            //Position.X += (float)Math.Sin(radians) * _velocity.NetForward;
            //Position.Y += _velocity.NetUpward;
            //Position.Z += (float)Math.Cos(radians) * _velocity.NetForward;
        }
    // Start is called before the first frame update
    void Start()
    {
        //Get the Renderer component from the new cube
        var myRenderer = GetComponent <Renderer>();

        //Call SetColor using the shader property name "_Color" and setting the color to red
        myRenderer.material.SetColor("_EmissionColor", Color.white * 1);
        myLightZone.SetActive(true);

        //Get current player velocity
        playerMovementInput = GameObject.Find("Jammo_Player").GetComponent <MovementInput>();
    }
        private Quaternion BuildRotationFromInput(MovementInput input)
        {
            var pitchDelta  = input.Pitch * cameraSettings.PitchSpeed;
            var newPitch    = pitchTransform.rotation.eulerAngles.x + pitchDelta;
            var pitchAdjust = newPitch > 180 ? -360 : 0;

            newPitch = Mathf.Clamp(newPitch + pitchAdjust, -cameraSettings.MaxPitch, -cameraSettings.MinPitch);

            var yawDelta = input.Yaw * cameraSettings.YawSpeed;
            var newYaw   = transform.rotation.eulerAngles.y + yawDelta;

            return(Quaternion.Euler(newPitch, newYaw, 0));
        }
Esempio n. 30
0
 public void CalculateMovement()
 {
     if (_gameplayCameraTransform.isSet)
     {
         Vector3 cameraForward = _gameplayCameraTransform.Transform.forward;
         cameraForward.y = 0f;
         Vector3 cameraRight = _gameplayCameraTransform.Transform.right;
         cameraRight.y = 0f;
         Vector3 adjustedMovement = cameraRight.normalized * _previousMovementInput.x + cameraForward.normalized * _previousMovementInput.y;
         MovementInput = Vector3.ClampMagnitude(adjustedMovement, 1f);
         MovementInput.Normalize();
     }
 }
Esempio n. 31
0
    // Start is called before the first frame update
    void Start()
    {
        Cursor.visible = false;

        input             = GetComponent <MovementInput>();
        anim              = GetComponent <Animator>();
        impulse           = cameraFreeLook.GetComponent <CinemachineImpulseSource>();
        postVolume        = Camera.main.GetComponent <PostProcessVolume>();
        postProfile       = postVolume.profile;
        swordOrigRot      = sword.localEulerAngles;
        swordOrigPos      = sword.localPosition;
        swordMesh         = sword.GetComponentInChildren <MeshRenderer>();
        swordMesh.enabled = false;
    }
Esempio n. 32
0
 //Default settings
 public void MakeDefault()
 {
     SelectKey = new GamepadInput(this, "SelectKey", Buttons.A, PlayerIndex.One);
     AnalogStick = new GamePadAnalog(this, "AnalogStick", Sticks.Right, PlayerIndex.One);
     UpKey = new GamepadInput(this, "UpKey", Buttons.DPadUp, PlayerIndex.One);
     DownKey = new GamepadInput(this, "DownKey", Buttons.DPadDown, PlayerIndex.One);
     LeftKey = new GamepadInput(this, "LeftKey", Buttons.DPadLeft, PlayerIndex.One);
     RightKey = new GamepadInput(this, "RightKey", Buttons.DPadRight, PlayerIndex.One);
     Input = MovementInput.Analog;
 }
Esempio n. 33
0
 /// <summary>
 /// Creates a new ControllerCursor with default values
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="name"></param>
 public ControllerCursor(MouseService parent, string name)
     : base(parent, name)
 {
     Input = MovementInput.Analog;
     MakeDefault();
 }
Esempio n. 34
0
        public override void Update(GameTime gt)
        {
            if (AutoSwitchInputs) //Switch the inputs
                if(Input != MovementInput.Analog && AnalogStickMoved())
                {
                    Input = MovementInput.Analog;
                    EntityGame.Log.Write("Input switched to Analog", this, Alert.Info);
                }
                else if(Input != MovementInput.Buttons && ButtonPressed())
                {
                    Input = MovementInput.Buttons;
                    EntityGame.Log.Write("Input switched to Buttons", this, Alert.Info);
                }

            switch (Input)
            {
                case MovementInput.Analog:
                    if (!HasFocus && (AnalogStickMoved() || SelectKey.Down()))
                        GetFocus(this);
                    if (HasFocus)
                    {
                        //TODO: Use normalized positition for this.
                        Position = new Vector2(Position.X + AnalogStick.Position.X*MovementSpeed.X,
                                               Position.Y - AnalogStick.Position.Y*MovementSpeed.Y);

                        //Move it with the camera.
                        //Position += EntityGame.Camera.Delta;

                        //Keep it from leaving the bounds of the window.
                        if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                            Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                        else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                            Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;

                        if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                            Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                        else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                            Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                    break;
                case MovementInput.Buttons:
                    if (!HasFocus && ButtonPressed() || SelectKey.Down())
                        GetFocus(this);
                    if (HasFocus)
                    {
                        Position = new Vector2(
                            Position.X + ((LeftKey.Down()) ? -MovementSpeed.X : 0) + ((RightKey.Down()) ? MovementSpeed.X : 0),
                            Position.Y + ((UpKey.Down()) ? -MovementSpeed.Y : 0) + ((DownKey.Down()) ? MovementSpeed.Y : 0)
                            );

                        //Move it with the camera.
                        Position += EntityGame.ActiveCamera.Delta;

                        //Keep it from leaving the bounds of the window.
                        if (Body.Position.X < EntityGame.ActiveCamera.ScreenSpace.Left)
                            Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Left;
                        else if (Body.BoundingRect.Right > EntityGame.ActiveCamera.ScreenSpace.Right)
                            Body.Position.X = EntityGame.ActiveCamera.ScreenSpace.Right - Body.Bounds.X;

                        if (Body.Position.Y < EntityGame.ActiveCamera.ScreenSpace.Top)
                            Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Top;
                        else if (Body.BoundingRect.Bottom > EntityGame.ActiveCamera.ScreenSpace.Bottom)
                            Body.Position.Y = EntityGame.ActiveCamera.ScreenSpace.Bottom - Body.Bounds.Y;
                    }
                    break;
            }
            base.Update(gt);
        }