// Update is called once per frame void Update() { if (m_movement.canMove) { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); Vector2 inp = new Vector2(inputX, inputY); if (inputY > 0.5) { direction.y = 1; } else if (inputY < -0.5) { direction.y = -1; } if (inputX > 0.5) { direction.x = 1; } else if (inputX < -0.5) { direction.x = -1; } Vector2 targetVel = inp * moveSpeed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVel.x, ref velocityXSmoothing, acceleration); velocity.y = Mathf.SmoothDamp(velocity.y, targetVel.y, ref velocityYSmoothing, acceleration); m_movement.Move(velocity, inp); if (Input.GetButtonDown("Fire1")) { if (velocity.magnitude < 0.1f) { m_fireControl.fire(lastMajorDir); } else { lastMajorDir = velocity.normalized; m_fireControl.fire(velocity.normalized); } } if (Input.GetButtonDown("Fire2")) { if (GetComponent <Attackable> ().pagesUsed < GetComponent <Attackable> ().maxPages) { LevelManager.Get().saveRoom(); GetComponent <Attackable> ().pagesUsed++; } } } }
// Update is called once per frame void Update() { float dist = Vector3.Distance(playerObj.transform.position, transform.position); if (dist < maxChaseDistance) { if (dist > minChaseDistance) { Vector3 otherPos = playerObj.transform.position; Vector3 myPos = transform.position; float xDiff = otherPos.x - myPos.x; float yDiff = otherPos.y - myPos.y; float angle = Mathf.Atan2(yDiff, xDiff); velocity = new Vector2(Mathf.Cos(angle) * moveSpeed, Mathf.Sin(angle) * moveSpeed); movement.Move(velocity, velocity.normalized); } m_fireControl.fire((playerObj.transform.position - transform.position).normalized); } }