// Update is called once per frame private void FixedUpdate() { if (path == null) { return; } if (stateMachine.currentState.stateName != "Play") { entityMovement.Move(0); return; } bool isTarget = false; float distanceToWaypoint = UpdateWaypoint(); float distanceToTarget = Vector3.Distance(rb2D.position, target.position); Vector2 offset; if (!reachedEndOfPath && distanceToWaypoint < distanceToTarget) { offset = (path.vectorPath[currentWaypoint] - transform.position).normalized; } else { isTarget = true; offset = (target.position - transform.position).normalized; } float xAxis = Mathf.Sign(offset.x); entityMovement.Move(xAxis); if (!isTarget && offset.y > 0.4f) { entityMovement.Jump(); } if (xAxis > 0f && direction == "left") { Flip("right"); } if (xAxis < 0f && direction == "right") { Flip("left"); } }
void Update() { var totalMovement = new Vector3(0f, Input.GetAxis("Vertical"), Input.GetAxis("Horizontal")); if (totalMovement.magnitude > 0f) { MovingEntity.Move(totalMovement); } if (Input.GetButtonDown("Miner")) { Systems.SwitchMode(); } if (Input.GetKeyDown(KeyCode.Tab)) { if (mapExpanded) { MapExpand.Shrink(); MapCamera.ZoomIn(); } else { MapExpand.Expand(); MapCamera.ZoomOut(); } mapExpanded = !mapExpanded; } if (Input.GetKeyDown(KeyCode.Escape)) { InGameMenu.SetActive(!InGameMenu.activeInHierarchy); } }
void Update() { player_movement.Move(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetMouseButtonDown(0)) { player_damage.Attack(Camera.main.ScreenToWorldPoint(Input.mousePosition)); } Flip(); IsAttack(); animator.SetFloat("move_x", Input.GetAxisRaw("Horizontal")); animator.SetFloat("move_y", Input.GetAxisRaw("Vertical")); animator.SetBool("attack_right_side", is_attack); }
public void Execute() { if (!isWandering) { if (currentWaitTime >= timeToWaitUntilNextWanderRequest) { entityMovement.Move(TerrainManager.instance.RequestPath(entity.transform.position, GetRandomLocationAroundArea())); isWandering = true; currentWaitTime = 0f; } else { currentWaitTime += Time.deltaTime; } } }
private void FixedUpdate() { entityMovement.Move(horizontalInput); if (stateMachine.currentState.stateName != "Play") { return; } if (horizontalInput > 0f && direction == "left") { Flip("right"); } if (horizontalInput < 0f && direction == "right") { Flip("left"); } }
public override void Execute() { if (!isWandering) { if (currentWaitTime >= timeToWaitUntilNextWanderRequest) { isWandering = true; moveAroundArea = TerrainManager.instance.GetTilePosGivenWorldPos(this.entity.transform.position); GetRandomLocationAroundArea(); Debug.Log(moveAroundArea); entityMovement.DestinationReachedHandler += HasArrivedAtDestination; entityMovement.DestinationNotReachableHandler += CantGoToDestination; entityMovement.Move(TerrainManager.instance.RequestPath(entity.transform.position, GetRandomLocationAroundArea())); currentWaitTime = 0f; } else { currentWaitTime += Time.deltaTime; } } }
void FollowTarget(GameObject target) { Vector2 direction = (target.transform.position - transform.transform.position).normalized; movement.Move(direction.x, direction.y); }