public void RunCommand(ref UserCMD cmd) { cmd.UpMove = 0f; Vector3 moveInputVector3 = Vector3.ClampMagnitude(new Vector3( cmd.RightMove, cmd.UpMove, cmd.ForwardMove ), 1f); Vector3 planarDirection = Vector3.ProjectOnPlane( cmd.Rotation * Vector3.forward, transform.up ).normalized; if (planarDirection.sqrMagnitude == 0f) { planarDirection = Vector3.ProjectOnPlane( cmd.Rotation * Vector3.up, transform.up ).normalized; } Quaternion planarRotation = Quaternion.LookRotation( planarDirection, transform.up ); var MovementInputVector = planarRotation * moveInputVector3; transform.rotation = Quaternion.Slerp(transform.rotation, cmd.Rotation, 1f - Mathf.Exp(-15f * Time.deltaTime)); m_Controller.Move(MovementInputVector); }
UserCMD CreateMove(int sequenceNumber) { UserCMD newMove = new UserCMD(); newMove.Sequence = sequenceNumber; //m_Sequences[sequenceNumber % 256] = newMove; newMove.ForwardMove = Input.GetAxisRaw("Vertical"); newMove.RightMove = Input.GetAxisRaw("Horizontal"); newMove.Rotation = transform.rotation; Vector3 rotationDelta = Vector3.zero; rotationDelta.y += Input.GetAxis("Mouse X") * 90f * 0.04f; m_ViewAngles += rotationDelta; while (m_ViewAngles.y > 180.0f) { m_ViewAngles.y -= 360.0f; } newMove.Rotation = Quaternion.Euler(m_ViewAngles); return(newMove); }
public void CmdSetCommand(UserCMD cmd) { m_Controller.RunCommand(ref cmd); }