Skip to content
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

Add functionality to center camera on player back #45

Open
wants to merge 1 commit into
base: main
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
17 changes: 13 additions & 4 deletions Source/Actors/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,20 @@ public override void Update()
{
// Rotate Camera
{
var rot = new Vec2(cameraTargetForward.X, cameraTargetForward.Y).Angle();
rot -= Controls.Camera.Value.X * Time.Delta * 4;
if (!Controls.BackCamera.Pressed)
{
var rot = new Vec2(cameraTargetForward.X, cameraTargetForward.Y).Angle();
rot -= Controls.Camera.Value.X * Time.Delta * 4;

var angle = Calc.AngleToVector(rot);
cameraTargetForward = new(angle, 0);
var angle = Calc.AngleToVector(rot);
cameraTargetForward = new(angle, 0);
}
else
{
var rot = Facing.Angle();
var angle = Calc.AngleToVector(rot);
cameraTargetForward = new(angle, 0);
}
}

// Move Camera in / out
Expand Down
9 changes: 7 additions & 2 deletions Source/Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public static class Controls
public static readonly VirtualButton Jump = new("Jump", .1f);
public static readonly VirtualButton Dash = new("Dash", .1f);
public static readonly VirtualButton Climb = new("Climb");
public static readonly VirtualButton BackCamera = new("BackCamera");

public static readonly VirtualButton Confirm = new("Confirm");
public static readonly VirtualButton Confirm = new("Confirm");
public static readonly VirtualButton Cancel = new("Cancel");
public static readonly VirtualButton Pause = new("Pause");

Expand All @@ -25,6 +26,10 @@ public static void Load()
Camera.AddRightJoystick(0, 0.50f, 0.70f);
Camera.Add(Keys.A, Keys.D, Keys.W, Keys.S);

BackCamera.Clear();
BackCamera.Add(0, Axes.LeftTrigger, 1, .4f);
BackCamera.Add(Keys.E);

Jump.Clear();
Jump.Add(0, Buttons.A, Buttons.Y);
Jump.Add(Keys.C);
Expand All @@ -36,7 +41,6 @@ public static void Load()
Climb.Clear();
Climb.Add(0, Buttons.LeftShoulder, Buttons.RightShoulder);
Climb.Add(0, Axes.RightTrigger, 1, .4f);
Climb.Add(0, Axes.LeftTrigger, 1, .4f);
Climb.Add(Keys.Z, Keys.V, Keys.LeftShift, Keys.RightShift);

Menu.Clear();
Expand All @@ -62,6 +66,7 @@ public static void Consume()
Move.Consume();
Menu.Consume();
Camera.Consume();
BackCamera.Consume();
Jump.Consume();
Dash.Consume();
Climb.Consume();
Expand Down