Skip to content

Commit

Permalink
Add Strafing (#16)
Browse files Browse the repository at this point in the history
* Add Straifing

* Fix Typo
  • Loading branch information
PNone authored Mar 7, 2023
1 parent 0425307 commit 9b63a15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum Device
static KeyCode kb1X = KeyCode.Period;
static KeyCode kb1Y = KeyCode.Slash;
static KeyCode kb1Start = KeyCode.Return;
static KeyCode kb1Strafe = KeyCode.N;

static KeyCode kb2Left = KeyCode.A;
static KeyCode kb2Right = KeyCode.D;
Expand All @@ -30,6 +31,7 @@ public enum Device
static KeyCode kb2X = KeyCode.U;
static KeyCode kb2Y = KeyCode.I;
static KeyCode kb2Start = KeyCode.Space;
static KeyCode kb2Strafe = KeyCode.R;


static float deadZone = 0.3f;
Expand Down Expand Up @@ -178,6 +180,7 @@ static void GetKeyboard1Input(InputState inputState)
inputState.aButton = Input.GetKey(kb1A);
inputState.bButton = Input.GetKey(kb1B);
inputState.start = Input.GetKey(kb1Start);
inputState.strafe = Input.GetKey(kb1Strafe);
}

static void GetKeyboard2Input(InputState inputState)
Expand Down Expand Up @@ -210,6 +213,7 @@ static void GetKeyboard2Input(InputState inputState)
inputState.aButton = Input.GetKey(kb2A);
inputState.bButton = Input.GetKey(kb2B);
inputState.start = Input.GetKey(kb2Start);
inputState.strafe = Input.GetKey(kb2Strafe);
}


Expand All @@ -235,6 +239,7 @@ static void GetGamepadInput(UnityEngine.InputSystem.Gamepad device, InputState i
inputState.leftTrigger = device.leftTrigger.ReadValue();
inputState.rightTrigger = device.rightTrigger.ReadValue();
inputState.start = device.startButton.isPressed;
inputState.strafe = device.leftShoulder.isPressed;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class InputState
{
// rename these variables (use F2)
public float xAxis, yAxis, leftTrigger, rightTrigger;
public bool aButton, bButton, xButton, yButton, up, down, left, right, start;
public bool aButton, bButton, xButton, yButton, up, down, left, right, start, strafe;

public bool wasAButton, wasBButton, wasXButton, wasYButton, wasUp, wasDown, wasLeft, wasRight, wasStart;
}
Expand Down
15 changes: 11 additions & 4 deletions HohimBrueh/Assets/Scripts/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ void RunPhysics()
RunPhysicsNormal();
}
velocityT = velocity * t;
if (state != CharacterState.Attacking && state != CharacterState.Tounge)
if (state != CharacterState.Attacking && state != CharacterState.Tounge && !input.strafe)
{
if (velocity.x > 0f)
facingDir = 1;
Expand All @@ -1060,6 +1060,7 @@ void RunPhysics()

jumpCooldownLeft -= t;

// TODO Add strafing here too?
if (state == CharacterState.Tounge)
{
if (tongueDir.x > 0)
Expand Down Expand Up @@ -1127,7 +1128,10 @@ void AddInputMotionNormal()

if (input.right && state == CharacterState.Normal)
{
facingDir = 1;
if (!input.strafe)
{
facingDir = 1;
}
if (onGround)
{
if (velocity.x < 0f)
Expand All @@ -1150,7 +1154,10 @@ void AddInputMotionNormal()
}
else if (input.left && state == CharacterState.Normal)
{
facingDir = -1;
if (!input.strafe)
{
facingDir = -1;
}
if (onGround)
{
if (velocity.x > 0f)
Expand Down Expand Up @@ -1202,7 +1209,7 @@ void AddInputMotionNormal()
}
}

if (attackState == AttackState.Charging)
if (attackState == AttackState.Charging && !input.strafe)
{
if (input.right)
{
Expand Down

0 comments on commit 9b63a15

Please sign in to comment.