diff --git a/PlayerPed.cs b/PlayerPed.cs index 24ca696..1434032 100644 --- a/PlayerPed.cs +++ b/PlayerPed.cs @@ -457,13 +457,14 @@ private void UpdateFoot() Vector3 dest = Vector3.Zero; if (TwoPlayerMod.customCamera) { - dest = Ped.Position - new Vector3(leftThumb.X, leftThumb.Y, 0); + dest = Ped.Position - TwoPlayerMod.AlterInput(new Vector3(leftThumb.X, leftThumb.Y, 0)); } else { - dest = Ped.GetOffsetInWorldCoords(new Vector3(leftThumb.X, leftThumb.Y, 0)); + dest = Ped.GetOffsetInWorldCoords(TwoPlayerMod.AlterInput(new Vector3(leftThumb.X, leftThumb.Y, 0))); } + Ped.Task.RunTo(dest, true, -1); resetWalking = true; } @@ -649,5 +650,7 @@ private void UpdateLastAction(PlayerPedAction action) { lastActions[action] = Game.GameTime; } + + } } \ No newline at end of file diff --git a/TwoPlayerMod.cs b/TwoPlayerMod.cs index 82c19df..690a786 100644 --- a/TwoPlayerMod.cs +++ b/TwoPlayerMod.cs @@ -44,6 +44,8 @@ class TwoPlayerMod : Script // camera public static bool customCamera = false; private Camera camera; + public enum CameraDirection { South, West, North, East } + public static CameraDirection camDirection = CameraDirection.South; // players private readonly UserIndex[] userIndices = new UserIndex[] { UserIndex.Two, UserIndex.Three, UserIndex.Four }; @@ -537,7 +539,7 @@ private void TwoPlayerMod_Tick(object sender, EventArgs e) offset *= 10; } Vector3 dest = Vector3.Zero; - dest = player1.Position - new Vector3(offset.X, offset.Y, 0); + dest = player1.Position - AlterInput(new Vector3(offset.X, offset.Y, 0)); player1.Task.RunTo(dest, true, -1); resetWalking = true; } @@ -547,6 +549,29 @@ private void TwoPlayerMod_Tick(object sender, EventArgs e) resetWalking = false; } } + if(customCamera) + { + //Change camera when Player 1 right stick + RB (unassigned controller) is moved or Q (cover on foot) / X (duck in vehicle) (defaults) + numpad. + if (Game.IsControlPressed(0, GTA.Control.Cover) || Game.IsControlPressed(0, GTA.Control.VehicleDuck)) + { + if (Game.IsControlPressed(0, GTA.Control.LookDownOnly) || Game.IsKeyPressed(Keys.NumPad2)) + { + ChangeCamera(CameraDirection.South); + } + if (Game.IsControlPressed(0, GTA.Control.LookLeftOnly) || Game.IsKeyPressed(Keys.NumPad4)) + { + ChangeCamera(CameraDirection.West); + } + if (Game.IsControlPressed(0, GTA.Control.LookUpOnly) || Game.IsKeyPressed(Keys.NumPad8)) + { + ChangeCamera(CameraDirection.North); + } + if (Game.IsControlPressed(0, GTA.Control.LookRightOnly) || Game.IsKeyPressed(Keys.NumPad6)) + { + ChangeCamera(CameraDirection.East); + } + } + } if (Game.IsControlJustReleased(0, GTA.Control.NextCamera)) { @@ -600,7 +625,31 @@ private void UpdateCamera() float dist = furthestPlayer.Ped.Position.DistanceTo(player1.Position); - center.Y += 5f + (dist / 1.6f); + //Switch location (direction = location + PointAt) of camera depending on camDirection + switch (camDirection) + { + case CameraDirection.South: + center.Y += 5f + (dist / 1.6f); + Function.Call(Hash.LOCK_MINIMAP_ANGLE, 0); + break; + case CameraDirection.West: + center.X += 5f + (dist / 1.6f); + Function.Call(Hash.LOCK_MINIMAP_ANGLE, 90); + break; + case CameraDirection.North: + center.Y -= 5f + (dist / 1.6f); + Function.Call(Hash.LOCK_MINIMAP_ANGLE, 180); + break; + case CameraDirection.East: + center.X -= 5f + (dist / 1.6f); + Function.Call(Hash.LOCK_MINIMAP_ANGLE, 270); + break; + default: + center.Y += 5f + (dist / 1.6f); + Function.Call(Hash.LOCK_MINIMAP_ANGLE, 0); + break; + } + center.Z += 2f + (dist / 1.4f); camera.Position = center; @@ -610,4 +659,75 @@ private void UpdateCamera() World.RenderingCamera = null; } } + + /// + /// Changes camera by 90 degrees clockwise + /// + public static void ChangeCamera(CameraDirection newDirection) + { + camDirection = newDirection; + } + + /// + /// Switches player input depending on camera orientation (Vector2) + /// + /// Offset prior to remapping + public static Vector2 AlterInput(Vector2 offset) + { + float temporaryOffset; + switch (camDirection) + { + case CameraDirection.South: //No need to change offset + break; + case CameraDirection.West: //Switch X and Y, make X negative + temporaryOffset = offset.X; + offset.X = offset.Y; + offset.Y = -temporaryOffset; + break; + case CameraDirection.North: //Make X and Y negative + offset.X = -offset.X; + offset.Y = -offset.Y; + break; + case CameraDirection.East: //Switch X and Y, make Y negative + temporaryOffset = offset.X; + offset.X = -offset.Y; + offset.Y = temporaryOffset; + break; + default: //Just in case + break; + } + return offset; + } + + /// + /// Switches player input depending on camera orientation (Vector3) + /// + /// Offset prior to remapping + public static Vector3 AlterInput(Vector3 offset) + { + float temporaryOffset; + switch (camDirection) + { + case CameraDirection.South: //No need to change offset + break; + case CameraDirection.West: //Switch X and Y, make X negative + temporaryOffset = offset.X; + offset.X = offset.Y; + offset.Y = -temporaryOffset; + break; + case CameraDirection.North: //Make X and Y negative + offset.X = -offset.X; + offset.Y = -offset.Y; + break; + case CameraDirection.East: //Switch X and Y, make Y negative + temporaryOffset = offset.X; + offset.X = -offset.Y; + offset.Y = temporaryOffset; + break; + default: //Just in case + break; + } + return offset; + } + } \ No newline at end of file