Skip to content

Implemented camera controls to face compass points #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions PlayerPed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -649,5 +650,7 @@ private void UpdateLastAction(PlayerPedAction action)
{
lastActions[action] = Game.GameTime;
}


}
}
124 changes: 122 additions & 2 deletions TwoPlayerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
}
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
Expand All @@ -610,4 +659,75 @@ private void UpdateCamera()
World.RenderingCamera = null;
}
}

/// <summary>
/// Changes camera by 90 degrees clockwise
/// </summary>
public static void ChangeCamera(CameraDirection newDirection)
{
camDirection = newDirection;
}

/// <summary>
/// Switches player input depending on camera orientation (Vector2)
/// </summary>
/// <param name="offset">Offset prior to remapping</param>
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;
}

/// <summary>
/// Switches player input depending on camera orientation (Vector3)
/// </summary>
/// <param name="offset">Offset prior to remapping</param>
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;
}

}