protected virtual void Update() { if (m_Controller != null) { float horizontalComp = Input.GetAxis(GetPlayerControl(m_ControlMap) + "Horizontal"); float verticalComp = Input.GetAxis(GetPlayerControl(m_ControlMap) + "Vertical"); float interactionComp = Input.GetAxis(GetPlayerControl(m_ControlMap) + "Interaction"); // if(Mathf.Abs(horizontalComp) > 0.01f || Mathf.Abs(verticalComp) > 0.01f) { PlayerInputEventData eventData = new PlayerInputEventData(); eventData._type = PlayerInputAction.MOVE; Dictionary <string, float> values = new Dictionary <string, float>(); values.Add("horizontal", horizontalComp); values.Add("vertical", verticalComp); eventData._data = values; SendMessage("OnPlayerInput", eventData, SendMessageOptions.DontRequireReceiver); } if (Mathf.Abs(interactionComp) > 0.01f) { PlayerInputEventData eventData = new PlayerInputEventData(); eventData._type = PlayerInputAction.INTERACTION; SendMessage("OnPlayerInput", eventData, SendMessageOptions.DontRequireReceiver); } } }
private void OnPlayerInput(PlayerInputEventData eventData) { switch (eventData._type) { case PlayerInputAction.MOVE: { if (CanProcessState(PlayerState.RUNNING) && m_CurrentState != PlayerState.CHOPPING) { Dictionary <string, float> values = (Dictionary <string, float>)eventData._data; float horizontalComp = values["horizontal"]; float verticalComp = values["vertical"]; if (Mathf.Abs(horizontalComp) > 0.01f || Mathf.Abs(verticalComp) > 0.01f) { Vector3 targetDirection = horizontalComp * Vector3.right + verticalComp * Vector3.forward; m_MoveDirection = Vector3.RotateTowards(m_MoveDirection, targetDirection, m_TurnRate * Mathf.Deg2Rad * Time.deltaTime, 1000); m_MoveDirection = m_MoveDirection.normalized; if (Mathf.Abs(horizontalComp) > 0.1f || Mathf.Abs(verticalComp) > 0.1f) { Vector3 movement = m_MoveDirection * m_MoveSpeed * Time.deltaTime + new Vector3(0, m_VerticalSpeed, 0); //transform.position += movement; m_RigidBody.MovePosition(transform.position + movement); } //transform.rotation = Quaternion.LookRotation(m_MoveDirection); m_RigidBody.MoveRotation(Quaternion.LookRotation(m_MoveDirection)); } else if (m_CurrentState == PlayerState.RUNNING) { SetState(PlayerState.IDLE); } } break; } case PlayerInputAction.INTERACTION: { if (m_IsInsideTrigger) { SetState(PlayerState.INTERACTION); } } break; case PlayerInputAction.PAUSE: { break; } } }