/// <summary> /// Controlls the movement of the player /// </summary> private void MovementUpdate() { float hor = Input.GetAxis("Horizontal"); //A,D float vert = Input.GetAxis("Vertical"); //S,W //If the camera is a first person type if (PlayerCameraScript.CameraController is FirstPersonCC) { float dz = hor * Mathf.Sin(-Player.LookAngle * Mathf.Deg2Rad) + vert * Mathf.Cos(-Player.LookAngle * Mathf.Deg2Rad); float dx = hor * Mathf.Cos(-Player.LookAngle * Mathf.Deg2Rad) - vert * Mathf.Sin(-Player.LookAngle * Mathf.Deg2Rad); LoadedPlayer.MoveInDirection(new Vector2(dx, dz)); } else if (PlayerCameraScript.CameraController is ThirdPersonCC) { ThirdPersonCC cc = PlayerCameraScript.CameraController as ThirdPersonCC; float dz = -hor *Mathf.Sin((cc.Theta - 90) *Mathf.Deg2Rad) - vert * Mathf.Cos((cc.Theta - 90) * Mathf.Deg2Rad); float dx = -hor *Mathf.Cos((cc.Theta - 90) *Mathf.Deg2Rad) + vert * Mathf.Sin((cc.Theta - 90) * Mathf.Deg2Rad); LoadedPlayer.MoveInDirection(new Vector2(dx, dz)); } }
void Update() { if (Console.Instance != null && Console.Instance.Active) { return; } if (GameManager.GUIManager != null && GameManager.GUIManager.DialogGUI.InConversation) { return; } if (Input.GetKeyDown(KeyCode.P)) { doPath = true; } else { doPath = false; } if (Input.GetKeyDown(KeyCode.Return)) { GUIManager2.Instance.SetVisible(!GUIManager2.Instance.OpenGUIVisible); } if (GameManager.Paused) { return; } Debug.BeginDeepProfile("PlayerManagerUpdate"); Vector3 worldMousePos = GetWorldMousePosition(); Tick(Time.deltaTime); Player.Update(); MovementUpdate(); PlayerSelectUpdate(); /* * float x = Input.GetAxis("Horizontal"); * float z = Input.GetAxis("Vertical"); * * * float ud = x * Mathf.Cos(-PlayerCameraScript.Theta * Mathf.Deg2Rad) + z * Mathf.Sin(-PlayerCameraScript.Theta * Mathf.Deg2Rad); * float lr = x * Mathf.Sin(-PlayerCameraScript.Theta * Mathf.Deg2Rad) - z * Mathf.Cos(-PlayerCameraScript.Theta * Mathf.Deg2Rad); * * x *= Mathf.Cos(PlayerCameraScript.Theta * Mathf.Deg2Rad) + Mathf.Sin(PlayerCameraScript.Theta * Mathf.Deg2Rad); * z *= Mathf.Sin(PlayerCameraScript.Theta * Mathf.Deg2Rad); * * LoadedPlayer.MoveInDirection(new Vector2(lr, ud)); * */ GameManager.DebugGUI.SetData("world_mouse_pos", worldMousePos.ToString()); LoadedPlayer.LookTowardsPoint(worldMousePos); if (Input.GetKey(KeyCode.Alpha1)) { SpellCastData data = new SpellCastData(); data.Source = Player; data.Target = GetWorldMousePosition(); Player.CombatManager.SpellManager.CastSpell(0, data); } if (Input.GetMouseButtonDown(0)) { LeftMouseButton(); } else if (Input.GetMouseButtonDown(1)) { RightMouseButton(); } if (Input.GetKeyDown(KeyCode.Space)) { LoadedPlayer.Jump(); } LoadedPlayer.SetRunning(Input.GetKey(KeyCode.LeftShift)); Debug.EndDeepProfile("PlayerManagerUpdate"); }
void Update() { LoadedPlayer.SetIdle(false); if (Console.Instance != null && Console.Instance.Active) { return; } if (GUIManager.Instance != null && GUIManager.Instance.DialogGUI.InConversation) { Debug.Log(GUIManager.Instance.DialogGUI.InConversation); Debug.Log("Caused by GUI = true"); return; } if (Input.GetKeyDown(KeyCode.P)) { doPath = true; } else { doPath = false; } if (Input.GetKeyDown(KeyCode.Return)) { GUIManager.Instance.SetVisible(!GUIManager.Instance.OpenGUIVisible); } if (GameManager.Paused) { return; } if (Input.GetKeyDown(KeyCode.Tab)) { if (PlayerCameraScript.CameraController is FirstPersonCC) { PlayerCameraScript.SetThirdPersonCamera(); } else { PlayerCameraScript.SetFirstPersonCamera(); } } // Debug.BeginDeepProfile("PlayerManagerUpdate"); Vector3 worldMousePos = GetWorldMousePosition(); Vec2i currentChunk = World.GetChunkPosition(Player.TilePos); if (currentChunk != LastChunk) { LastChunk = currentChunk; } Tick(Time.deltaTime); Player.Update(); MovementUpdate(); PlayerSelectUpdate(); DebugGUI.Instance.SetData("world_mouse_pos", worldMousePos.ToString()); LoadedPlayer.LookTowardsPoint(worldMousePos); if (Input.GetKey(KeyCode.Alpha1)) { SpellCastData data = new SpellCastData(); data.Source = Player; data.Target = GetWorldMousePosition(); Player.CombatManager.EntitySpellManager.CastSpell(0, data); } if (Input.GetMouseButton(0)) { LeftMouseButton(); } else if (Input.GetMouseButtonDown(1)) { RightMouseButton(); } if (Input.GetKeyDown(KeyCode.Space)) { LoadedPlayer.Jump(); } LoadedPlayer.SetRunning(Input.GetKey(KeyCode.LeftShift)); Debug.EndDeepProfile("PlayerManagerUpdate"); }