void Update() { // Clamps the rotation // Gets input from screen var mouseDelta = new Vector2(CnInputManager.GetAxisRaw("HorizontalLook"), -CnInputManager.GetAxisRaw("VerticalLook")); // makes the mouse slower/less sensitive mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y)); // makes the mouse smooth smoothMouse.x = Mathf.Lerp(smoothMouse.x, mouseDelta.x, 1f / smoothing.x); smoothMouse.y = Mathf.Lerp(smoothMouse.y, mouseDelta.y, 1f / smoothing.y); // Finds mouse movement mouseAbsolute += smoothMouse; // Clams the mouse if (clampInDegrees.x < 360) { mouseAbsolute.x = Mathf.Clamp(mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f); } var xRotation = Quaternion.AngleAxis(-mouseAbsolute.y, 1 * Vector3.right); transform.localRotation = xRotation; // Then clamp and apply the global y value. if (clampInDegrees.y < 360) { mouseAbsolute.y = Mathf.Clamp(mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f); } }
// 입력 -> 이동 기능 public void InputMove() { // float 방향 = Input.GetAxisRaw("수평/수직") // 방향 : -1, 0, 1 (소수없음) //float h = Input.GetAxisRaw("Horizontal"); //float v = Input.GetAxisRaw("Vertical"); float h = CnInputManager.GetAxisRaw("Horizontal"); float v = CnInputManager.GetAxisRaw("Vertical"); // 2차원 방향 벡터 생성 Vector2 direction = new Vector2(h, v); // Transform.Translate(방향벡터 * 속도 * Time.deltaTime); // Transform 컴포넌트에게 이동을 요청함 (위임) transform.Translate(direction * _speed * Time.deltaTime); // 화면 경계 이동 제한 처리 Vector2 pos = transform.position; if (Mathf.Abs(pos.x) > LIMIT_POS_X) { pos.x = Mathf.Sign(pos.x) * LIMIT_POS_X; } if (Mathf.Abs(pos.y) > LIMIT_POS_Y) { pos.y = Mathf.Sign(pos.y) * LIMIT_POS_Y; } transform.position = pos; }
public void MovePlayer() { if (!GameManager.instance.playerCanMove) { return; } // Keyboard Input //int horizontal = (int)Input.GetAxisRaw("Horizontal"); //int vertical = (int)Input.GetAxisRaw("Vertical"); // For Mobile Input using CNControl horizontal = (int)CnInputManager.GetAxisRaw("Horizontal"); vertical = (int)CnInputManager.GetAxisRaw("Vertical"); if (horizontal != 0) { vertical = 0; } if (horizontal != 0 || vertical != 0) { AttemptToMove <Wall>(horizontal, vertical); isPlayerMoving = true; } if (horizontal == 0 && vertical == 0) { isPlayerMoving = false; } }
private void FixedUpdate() { //float moveHorizontal = Input.GetAxisRaw("Horizontal"); float moveHorizontal = CnInputManager.GetAxisRaw("Horizontal"); _rigidbody2D.velocity = new Vector2(moveHorizontal * speed, _rigidbody2D.velocity.y); }
private void _ready(IEntity entity) { var isDashing = CnInputManager.GetButtonDown("Dash"); if (isDashing) { var playerComponent = entity.GetComponent <PlayerComponent>(); var viewComponent = entity.GetComponent <ViewComponent>(); var go = viewComponent.View.gameObject; var rigidbody2D = go.GetComponent <Rigidbody2D>(); var directionVector = new Vector2( CnInputManager.GetAxisRaw("DirectionHorizontal"), CnInputManager.GetAxisRaw("DirectionVertical") ); var ghostEffect = go.GetComponent <GhostEffect>(); directionVector = directionVector.sqrMagnitude > 0.001f ? directionVector : (Vector2)go.transform.up; _originalVelocity = rigidbody2D.velocity; rigidbody2D.velocity = directionVector.normalized * 3.5f; ghostEffect.ghostingEnabled = true; playerComponent.isDashing = true; _dashState = DashState.Dashing; } }
// Update is called once per frame void Update() { if (ifCanMoove) { horizontalMove = CnInputManager.GetAxisRaw("Horizontal") * Speed; animator.SetFloat("Speed", Mathf.Abs(CnInputManager.GetAxisRaw("Horizontal"))); } #if UNITY_ANDROID if (CnInputManager.GetButtonDown("Run") && controller.m_Grounded) { stateSpeed = !stateSpeed; animator.SetBool("Run", stateSpeed); Speed = stateSpeed? runSpeed:walkSpeed; } //} else if (CnInputManager.GetButtonUp("Run")) { // animator.SetBool("Run", false); // Speed = walkSpeed; //} #else if (CnInputManager.GetButton("Run") && controller.m_Grounded) { animator.SetBool("Run", true); Speed = runSpeed; } else if (CnInputManager.GetButtonUp("Run")) { animator.SetBool("Run", false); Speed = walkSpeed; } #endif //GetSword if (CnInputManager.GetButtonDown("GetSword")) { animator.SetBool("Swording", !animator.GetBool("Swording")); AttakBTN.SetActive(animator.GetBool("Swording")); } if (animator.GetBool("Swording") && CnInputManager.GetButtonDown("Fire1") && forAttack) { animator.SetTrigger("Attack"); sword.SetActive(true); StartCoroutine(WaitSecfloat(1f)); } if (CnInputManager.GetButtonDown("Jump")) { jump = true; } }
private void Turn() { float h = CnInputManager.GetAxisRaw("Horizontal2"); float v = CnInputManager.GetAxisRaw("Vertical2"); if (h != 0 || v != 0) { Debug.Log(this.GetMethodName() + ":" + this.side); } this.move.Turn(h, v); }
void FixedUpdate() { // float h = Input.GetAxisRaw("Horizontal"); // float v = Input.GetAxisRaw("Vertical"); // Mobile Device Input float h = CnInputManager.GetAxisRaw("Horizontal"); float v = CnInputManager.GetAxisRaw("Vertical"); Moving(h, v); }
public static void ReadInputs(PlayerController player) { player.accelerate = CnInputManager.GetButton("Accelerate"); player.Turn(CnInputManager.GetAxisRaw("Rotate")); if (CnInputManager.GetButton("Shoot")) { player.CmdShoot(); } }
/// <summary> /// Handles the input of player character. /// Maintains character momentum, as values are constantly updated, rather than /// only on press or release. /// </summary> private void handleMovement() { //Check if we are running either in the Unity editor or in a standalone build. float vMotion = CnInputManager.GetAxisRaw("Vertical") * playerSpeed; float hMotion = CnInputManager.GetAxisRaw("Horizontal") * playerSpeed; vMotion *= Time.deltaTime; hMotion *= Time.deltaTime; transform.Translate(hMotion, vMotion, 0f); }
/// <summary> /// Handles the player firing - both Bullets and Whispers. /// </summary> private void handleFiring() { /* * Left Click handler, for bullet firing */ if (CnInputManager.GetButtonDown("Jump")) { /* Initialise values to store raycast */ RaycastHit rayHit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool mouseRayCheck = Physics.Raycast(ray, out rayHit, 1000); /* If ray makes contact with world, determine vector between mouseposition and player */ if (mouseRayCheck && !isPaused) { /* Assign values to shootVector variable */ shootVector.x = 0; shootVector.y = 1;; /* Normalize to bound vector values and make scaling uniform */ shootVector.Normalize(); /* Instantiate bullet using existing prefab, at current player location */ bulletInstance = Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject; bulletInstance.GetComponent <Bullet>().fireBullet(shootVector, quadName); /* Destroy the particular instance after 1.5 seconds */ Destroy(bulletInstance, 0.25f); } } /* * Right Click handler, for placing Whisper */ else if (Input.GetMouseButtonDown(0) && CnInputManager.GetAxisRaw("Horizontal") == 0f && CnInputManager.GetAxisRaw("Vertical") == 0f) { RaycastHit rayHit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool mouseRayCheck = Physics.Raycast(ray, out rayHit, 1000); bool quadTag = rayHit.transform.CompareTag("Quad"); if (mouseRayCheck && quadTag && !isPaused) { string whisperQuadName = rayHit.collider.gameObject.name + "_Whisper"; GameObject whisperObject = GameObject.Find(whisperQuadName); whisperObject.gameObject.GetComponent <WhisperController>().activateWhisper(); canPlaceWhisper = false; } } }
void Update() { if (!allowedToMove) { return; } float horizontal = 0.0f; float vertical = 0.0f; #if UNITY_STANDALONE || UNITY_WEBPLAYER horizontal = Input.GetAxisRaw("Horizontal"); vertical = Input.GetAxisRaw("Vertical"); #else horizontal = CnInputManager.GetAxisRaw("Horizontal"); vertical = CnInputManager.GetAxisRaw("Vertical"); #endif if (allowDiagonalMove == false) { if (horizontal > 0.5 || horizontal < -0.5) { vertical = 0.0f; } else { horizontal = 0.0f; } } Vector2 start = transform.position; Vector2 movementVector = new Vector2(horizontal, vertical); Vector2 end = start + movementVector; if (movementVector != Vector2.zero) { animator.SetBool("is_walking", true); SoundManager.instance.RandomizeSfx(moveSound1, moveSound2); animator.SetFloat("input_x", movementVector.x); animator.SetFloat("input_y", movementVector.y); } else { animator.SetBool("is_walking", false); } Vector2 newPostion = Vector2.MoveTowards(rb2D.position, end, inverseMoveTime * Time.deltaTime); rb2D.MovePosition(newPostion); }
void FixedUpdate() { float moveHorizontal = CnInputManager.GetAxisRaw("Horizontal"); float moveVertical = CnInputManager.GetAxisRaw("Vertical"); if (moveHorizontal == 0.0f && moveVertical == 0.0f) { moveHorizontal = Input.GetAxisRaw("Horizontal"); moveVertical = Input.GetAxisRaw("Vertical"); } movement.Set(moveHorizontal, 0.0f, moveVertical); movement = movement.normalized * speed * Time.deltaTime; rb.MovePosition(transform.position + movement); }
void UpdateMovement() { if (inPos != Vector3.zero && dir != Vector3.zero) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), turnSmooth * Time.deltaTime); } Transform camTrans = Camera.main.transform; Vector3 camForward = camTrans.TransformDirection(Vector3.forward); camForward.y = 0; camForward = camForward.normalized; Vector3 camRight = new Vector3(camForward.z, 0, -camForward.x); float cv = CnInputManager.GetAxisRaw("Vertical"); float ch = CnInputManager.GetAxisRaw("Horizontal"); dir = ch * camRight + cv * camForward; }
// Update is called once per frame void Update() { /* * horizontalMove = Input.GetAxisRaw("Horizontal"); * verticalMove = Input.GetAxisRaw("Vertical"); */ horizontalMove = CnInputManager.GetAxisRaw("Horizontal"); verticalMove = CnInputManager.GetAxisRaw("Vertical"); if (Input.GetButtonDown("Jump")) { isJumping = true; } AnimationUpdate(); }
void Update() { float h = CnInputManager.GetAxisRaw("Horizontal"); float v = CnInputManager.GetAxisRaw("Vertical"); inPos = new Vector3(h, 0, v); if (h != 0 || v != 0) { anim.SetBool("moving", true); } else { anim.SetBool("moving", false); } UpdateMovement(); footsound(); }
// Update is called once per frame void Update() { Vector2 movement_vector = new Vector2(CnInputManager.GetAxisRaw("Horizontal"), CnInputManager.GetAxisRaw("Vertical")); if (movement_vector != Vector2.zero) { anim.SetBool("iswalking", true); anim.SetFloat("input_x", movement_vector.x); anim.SetFloat("input_y", movement_vector.y); } else { anim.SetBool("iswalking", false); } rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime); }
private void _rotate(GameObject go) { var rotationVector = new Vector2( CnInputManager.GetAxisRaw("RotationHorizontal"), CnInputManager.GetAxisRaw("RotationVertical") ); if (rotationVector != Vector2.zero) { var speed = 12; var angle = Mathf.Atan2(rotationVector.x, rotationVector.y) * Mathf.Rad2Deg; var q = Quaternion.AngleAxis(angle, -Vector3.forward); go.transform.rotation = Quaternion.Slerp( go.transform.rotation, q, Time.deltaTime * speed ); } }
private void _move(GameObject go, IEntity entity) { var directionVector = new Vector2( CnInputManager.GetAxisRaw("DirectionHorizontal"), CnInputManager.GetAxisRaw("DirectionVertical") ); Debug.Log(directionVector.x); if (directionVector.sqrMagnitude > 0.001f) { var speed = 12f; var directionVectorNormalized = directionVector.normalized; var rigidbody2d = go.GetComponent <Rigidbody2D>(); rigidbody2d.AddForce(directionVectorNormalized * speed, ForceMode2D.Force); } }
void Update() { Vector2 input = new Vector2(CnInputManager.GetAxisRaw("Horizontal"), 0f); transform.Translate(input * Time.deltaTime * 10); if (transform.position.x < -screenHalfWidthInWorldUnits) { transform.position = new Vector2(screenHalfWidthInWorldUnits, transform.position.y); //if player must not move out of camera bounds(look at signs) //transform.position = new Vector2 (-screenHalfWidthInWorldUnits, transform.position.y); } if (transform.position.x > screenHalfWidthInWorldUnits) { transform.position = new Vector2(-screenHalfWidthInWorldUnits, transform.position.y); //if player must not move out of camera bounds(look at signs) //transform.position = new Vector2 (screenHalfWidthInWorldUnits, transform.position.y); } }
protected override Vector2 GetExpectedVelocity() { //todo: разобраться, почему не всегда срабатывает прыжок //todo: возможно стоит перенести рассчет expectedVelocity в Update() и хранить в поле, здесь только возвращать Vector2 expectedVelocity = base.GetExpectedVelocity(); expectedVelocity.x = walkingSpeed * CnInputManager.GetAxisRaw("Horizontal"); if (CnInputManager.GetButtonDown("Jump") && Grounded) { expectedVelocity.y = jumpTakeOffSpeed; } else if (CnInputManager.GetButtonUp("Jump")) { if (VelocityCurrent.y > 0) { expectedVelocity.y = VelocityCurrent.y * 0.5f; } } return(expectedVelocity); //move * maxSpeed; }
/// <summary> /// Method is run once per physics frame and updates the position of the player by multiplying the force vectors /// with move time. /// </summary> private void FixedUpdate() { var inConversation = dialogueFlowchart.GetBooleanVariable("IN_CONVERSATION"); if (inConversation) { //CheckConversation(); //Configure the animation of the player _animator.SetFloat("MoveX", 0f); _animator.SetFloat("MoveY", 0f); } else if (_Journal.gameObject.activeSelf) { //do nothing } else { if (CnInputManager.GetButtonDown("Esc") || Input.GetKeyUp(KeyCode.Escape)) { _Journal.GetComponent <Journal>().OpenJournal(); } // Get X and Y vectors var moveHorizontal = Input.GetAxisRaw("Horizontal") + CnInputManager.GetAxisRaw("H"); var moveVertical = Input.GetAxisRaw("Vertical") + CnInputManager.GetAxisRaw("V"); // If vectors are non-zero if (moveVertical != 0 || moveHorizontal != 0) { // then figure out the sum var movement = new Vector3(moveHorizontal, moveVertical, 0f); // multiply by movement time and sum the old position with the change in position transform.Translate(movement * MoveTime); _soundManager.PlaySound(_walkingSound); } //Configure the animation of the player _animator.SetFloat("MoveX", Input.GetAxisRaw("Horizontal") + CnInputManager.GetAxisRaw("H")); _animator.SetFloat("MoveY", Input.GetAxisRaw("Vertical") + CnInputManager.GetAxisRaw("V")); } }
/// <summary> /// Touchscreen update function /// </summary> private void touchUpdate() { if (this.player != null) { #region Player Movement float x = -CnInputManager.GetAxis("Horizontal"); if (x != 0f) { this.commandHandler.AddCommands(new CommandRotate(this.movement, this.movement.RotVel * x)); } float y = CnInputManager.GetAxis("Vertical"); if (y != 0f) { this.commandHandler.AddCommands(new CommandAccelerateDirectional(this.movement, this.movement.Thrust * y)); } #endregion Player Movement #region Player Shooting if (CnInputManager.GetButton("Shoot")) { this.commandHandler.AddCommands(new CommandShoot(this.weapons, 0, 1)); } #endregion Player Shooting } else { } #region Camera this.zoom.ChangeZoom(CnInputManager.GetAxisRaw("Zoom")); #endregion Camera }
// Update is called once per frame void Update() { if ((score.scoreAmount == 50) || (score.scoreAmount == 100) || (score.scoreAmount == 200)) { kek = count; } if ((score.scoreAmount == 51) || (score.scoreAmount == 101) || (score.scoreAmount == 201)) { count = 1; } if (kek == 1) { speed = speed + 0.3f; kek = 0; count = 0; } Vector2 moveInput = new Vector2(CnInputManager.GetAxisRaw("Horizontal"), CnInputManager.GetAxisRaw("Vertical")); moveVelocity = moveInput.normalized * speed; rb.MovePosition(rb.position + moveVelocity * speed * Time.deltaTime); }
void InputMovement() { int horizontal = 0; int vertical = 0; horizontal = (int)(CnInputManager.GetAxisRaw("Horizontal")); vertical = (int)(CnInputManager.GetAxisRaw("Vertical")); if (horizontal == 0 && vertical == 0) { horizontal = (int)(Input.GetAxisRaw("Horizontal")); vertical = (int)(Input.GetAxisRaw("Vertical")); } if (horizontal != 0) { vertical = 0; } if (horizontal != 0 || vertical != 0) { playersTurn = false; AttempMove(horizontal, vertical); } }
public void FixedUpdate() { Vector2 currentVelocity = _rigidBody.velocity; currentVelocity.x = WalkingSpeed * CnInputManager.GetAxisRaw("Horizontal"); Direction directionBeforeUpdate = _direction; if (currentVelocity.x > 0) { _direction = Direction.Right; } if (currentVelocity.x < 0) { _direction = Direction.Left; } if (directionBeforeUpdate != _direction) { FlipSprite(); } if (_jumpNextFixedUpdate) { currentVelocity.y = JumpTakeOffSpeed; _jumpNextFixedUpdate = false; } else if (CnInputManager.GetButtonUp("Jump")) { if (currentVelocity.y > 0) { currentVelocity.y = currentVelocity.y * 0.5f; } } _rigidBody.velocity = currentVelocity; }
void Update() { h = CnInputManager.GetAxisRaw("Horizontal"); v = CnInputManager.GetAxisRaw("Vertical"); isWalk = Mathf.Abs(h) > 0.1 || Mathf.Abs(v) > 0.1; if (isWalk) { if (isRun) { isRun = !(Mathf.Abs(h) > 0.9 || Mathf.Abs(v) > 0.9); player.health++; player.attack++; } else { isRun = (Mathf.Abs(h) > 0.9 || Mathf.Abs(v) > 0.9); } } else { isRun = false; } }
private Boolean _canFire(IEntity entity) { var playerComponent = entity.GetComponent <PlayerComponent>(); var rotationVector = new Vector2( CnInputManager.GetAxisRaw("RotationHorizontal"), CnInputManager.GetAxisRaw("RotationVertical") ); playerComponent.lastFireTime += Time.deltaTime; if (rotationVector == Vector2.zero) { return(false); } if (playerComponent.lastFireTime < playerComponent.fireRateTime) { return(false); } playerComponent.lastFireTime = 0; return(true); }
protected bool IsGoingLeft() { if (localPlayer) { bool buttonLeftPressed = CnInputManager.GetAxisRaw("Horizontal") == -1f; // si el wn esta apuntando hacia arriba/abajo con menor inclinacion que hacia la derecha, start moving if (buttonLeftPressed && !remoteLeft) { remoteLeft = true; remoteRight = false; SendPlayerDataToServer(); } // si no se esta apretando el joystick else if (!buttonLeftPressed && remoteLeft) { remoteLeft = false; SendPlayerDataToServer(); } } return(remoteLeft); }
// Update is called once per frame void Update() { if (onRope) { float H = CnInputManager.GetAxis("Horizontal"); //make player's position and rotation same as connected chain's playerTransform.position = collidedChain.position; playerTransform.localRotation = Quaternion.AngleAxis(direction, Vector3.forward); //if up button is pressed and "chainIndex > 1" (there is another chain above player), climb up if (CnInputManager.GetAxisRaw("Vertical") > 0 && chainIndex > 1) { timer += Time.deltaTime; if (timer > climbUpInterval) { ClimbUp(); timer = 0.0f; } } //if down button is pressed and "chainIndex < 1" (there is another chain below player), climb down if (CnInputManager.GetAxisRaw("Vertical") < 0) { if (chainIndex < chains.Count - 2) // -1 до последней -2 до предпоследней --- заставить не спускаться на самую нижнюю ступень { timer += Time.deltaTime; if (timer > climbUpInterval) { ClimbDown(); timer = 0.0f; } } else { //ClimbUp(); // заставить не спускаться на самую нижнюю ступень //StartCoroutine(JumpOff()); //if there isn't chain below player, jump from rope падение с веревки если дошел до ее конца с низу } } //if jump button is pressed, jump from rope if (CnInputManager.GetButtonDown("Jump")) { StartCoroutine(JumpOff()); if (!characterController.m_FacingRight) { m_Rigidbody2D.AddForce(new Vector2(-AddForceX, AddForceY)); } else if (characterController.m_FacingRight) { m_Rigidbody2D.AddForce(new Vector2(AddForceX, AddForceY)); } //characterController.Jump(H); //player.jump = true; } // Cache the horizontal CnInputManager. if (H > 0 && !characterController.m_FacingRight) { // ... flip the player. characterController.Flip(); } // Otherwise if the input is moving the player left and the player is facing right... else if (H < 0 && characterController.m_FacingRight) { // ... flip the player. characterController.Flip(); } //add swing force to connected chain collidedChain.GetComponent <Rigidbody2D>().AddForce(Vector2.right * H * swingForce); } }