private void OnDone() { if (state == NPCState.Follow) { return; } SetState(NPCState.Idling); characterMover.Move(Vector2.zero); StartCoroutine(PoiDelay(poiDelay)); }
private IEnumerator Investigate(Distraction distraction, bool run) { investigating = true; cc.Move(0, 0, false, false); yield return(new WaitForSeconds(investigationDelay)); navAgent.SetDestination(distraction.transform.position); while (navAgent.pathPending) { yield return(null); } var time = investigationDuration; while (true) { OnNavigate(run); if (navAgent.remainingDistance < navAgent.stoppingDistance) { if (time > 0) { time -= Time.deltaTime; } else { cc.Move(0, 0, false, false); yield return(new WaitForSeconds(investigationDuration)); distraction.Stop(); currentDistraction = null; BeginPatrol(); investigating = false; break; } } yield return(null); } }
private void FixedUpdate() { var inputDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); var relativeInput = Quaternion.Euler(0, camera.transform.eulerAngles.y, 0) * inputDir; mover.Move(relativeInput.x, relativeInput.z, Input.GetButton("Sprint"), Input.GetButton("Crouch")); if (relativeInput.sqrMagnitude > 0) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativeInput), Time.fixedDeltaTime * 5f); } }
public IEnumerator Move() { ShowMove(); ToggleWindow(false, false); QuadTile target = null; // Wait for click while (!target) { if (Input.GetButtonDown("Fire1")) { target = QuadTileMap.GetTarget(LayerMask.GetMask("Viable Marker")); } yield return(null); } mover.StopUpdatingPath = true; ConfirmationDialog dialog = Instantiate(dialogPrefab, transform.parent); // Wait for dialog input while (dialog.Result == DialogResult.None) { yield return(null); } if (dialog.Result == DialogResult.Yes) { Destroy(dialog.gameObject); CharacterData data = turnManager.CurrentCharacter.Data; MoveParams moveParams = moved ? data.rushParams : data.moveParams; yield return(StartCoroutine(mover.Move(turnManager.CurrentCharacter, target.Path(), moveParams, data.jumpParams))); turnManager.CurrentCharacter.LoseActionPoints(moveCost); moveCost++; if (moved) { MoveButton.interactable = false; } moved = true; } else { Destroy(dialog.gameObject); } mover.Clear(PathfindingClear.Both); ToggleWindow(true, false); }
void Update() { // ============== MOVEMENT ====================== float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector2 move = new Vector2(horizontal, vertical); playFootSteps = move != Vector2.zero; characterMover.Move(move); // ============== ACTIONS ====================== // if (Input.GetKeyDown(actionKey1)) // DoAction1(); // else if (Input.GetKeyDown(actionKey2)) // DoAction2(); // else if (Input.GetKeyDown(actionKey3)) // DoAction3(); // else if (Input.GetKeyDown(actionKey4)) // DoAction4(); /* * // ======== DIALOGUE ========== * if (Input.GetKeyDown(KeyCode.X)) * { * RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, 1 << LayerMask.NameToLayer("NPC")); * if (hit.collider != null) * { * NonPlayerCharacter character = hit.collider.GetComponent<NonPlayerCharacter>(); * if (character != null) * { * character.DisplayDialog(); * } * } * } */ // if (Input.GetKeyDown(KeyCode.Alpha0)) // { // if (npcController.allowDebug) // { // BecomeUnplayable(); // npcController.SetState(NPCState.Moving); // } // } }
private void Update() { float deltaTime = Time.deltaTime; Vector3 movementInput = GetMovementInput(); Vector3 velocity = moveSpeed * movementInput; bool groundDetected = DetectGroundAndCheckIfGrounded(out bool isGrounded, out GroundInfo groundInfo); SetGroundedIndicatorColor(isGrounded); isOnMovingPlatform = false; if (isGrounded && Input.GetButtonDown("Jump")) { verticalSpeed = jumpSpeed; nextUngroundedTime = -1f; isGrounded = false; } if (isGrounded) { mover.isInWalkMode = true; verticalSpeed = 0f; if (groundDetected) { isOnMovingPlatform = groundInfo.collider.TryGetComponent(out movingPlatform); } } else { mover.isInWalkMode = false; BounceDownIfTouchedCeiling(); verticalSpeed += gravity * deltaTime; if (verticalSpeed < minVerticalSpeed) { verticalSpeed = minVerticalSpeed; } velocity += verticalSpeed * transform.up; } RotateTowards(velocity); mover.Move(velocity * deltaTime, moveContacts, out contactCount); }
void Move() { smoothMovement = Vector2.Lerp(smoothMovement, movement, Time.fixedDeltaTime * 10); Vector3 velocity = new Vector3(); velocity.x = smoothMovement.x; velocity.z = smoothMovement.y; velocity = Vector3.Lerp(facing.TransformDirection(velocity), character.TransformDirection(velocity), movementSmoothness); float targetSpeed = movementSpeed * currentStance.Speed; currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Time.fixedDeltaTime * 5); if (velocity.magnitude > 1) { velocity.Normalize(); } velocity *= currentSpeed; velocity = currentStance.OnMove(velocity); mover.Move(velocity * Time.fixedDeltaTime, out lastVelocity); }
private void MoveAction() { _CharacterMover.Move(_horizontalMove, _isJump); _isJump = false; SetAnimationMove(); }
//Action public void Move(float move, bool jump) { mover.Move(move, jump); }