Skip to content

Commit

Permalink
fixed dash line when using controller
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSalm committed Jul 21, 2024
1 parent a91d4ef commit 6bf9f2a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
44 changes: 44 additions & 0 deletions Dust Bunny/Assets/Scripts/Input/Controls.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "0e4c3537-eb30-42ab-be80-f27b38511fa3",
"path": "<Gamepad>/leftShoulder",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Dash",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "555a5b97-552d-4ab2-87d1-f5f0ae28846a",
"path": "<Gamepad>/leftTrigger",
"interactions": "",
"processors": "",
"groups": "",
"action": "Dash",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "746486e1-a73d-4df6-9a2b-fa1b0116bb1b",
Expand Down Expand Up @@ -145,6 +167,28 @@
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "43e99718-1812-4ef2-9347-7b867710d166",
"path": "<Gamepad>/rightShoulder",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "01b7bbe4-d3bf-4451-864e-5ae518f5762d",
"path": "<Gamepad>/rightTrigger",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "070a91a9-d912-47bc-8862-26793990d48d",
Expand Down
39 changes: 26 additions & 13 deletions Dust Bunny/Assets/Scripts/Player/PlayerAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ private void HandleSquashAndStretch(){
//_sprite.transform.localScale = new Vector3(1, yScale, 1);
}

private Vector2 GetDashArrowTargetByMoveInput(Vector2 moveInput){
Vector2 dashTargetWorldPosition;
float dashLengthMod = 1 + (.8f * _player.Stats.DashDuration * _player.Stats.DashVelocity * transform.localScale.x);
if (moveInput.sqrMagnitude > 0.01f)
{
dashTargetWorldPosition = _arrowPivot.transform.position + (Vector3)(moveInput * dashLengthMod);
}
else
{
float mod = 1;
if (_sprite.flipX) mod = -1;
dashTargetWorldPosition = _arrowPivot.transform.position + new Vector3(mod * dashLengthMod, 0, 0);
}

return dashTargetWorldPosition;
}

private void HandleDashArrow()
{
float cameraZoom = Camera.main.orthographicSize;
Expand All @@ -176,23 +193,19 @@ private void HandleDashArrow()
Vector3 dashTargetWorldPosition;
if (UserInput.instance.UseMouseForDash)
{
dashTargetWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
dashTargetWorldPosition.z = 0;
FrameInput _frameInput = UserInput.instance.Gather();
if(_frameInput.DashDirectionGamepad.magnitude < 0.01f){
dashTargetWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
dashTargetWorldPosition.z = 0;
} else {
Vector2 moveInput = _frameInput.DashDirectionGamepad;
dashTargetWorldPosition = GetDashArrowTargetByMoveInput(moveInput);
}
}
else
{
Vector2 moveInput = dashTargetWorldPosition = UserInput.instance.Gather().Move;
float dashLengthMod = 1 + (.8f * _player.Stats.DashDuration * _player.Stats.DashVelocity * transform.localScale.x);
if (moveInput.sqrMagnitude > 0.001f)
{
dashTargetWorldPosition = _arrowPivot.transform.position + (Vector3)(moveInput * dashLengthMod);
}
else
{
float mod = 1;
if (_sprite.flipX) mod = -1;
dashTargetWorldPosition = _arrowPivot.transform.position + new Vector3(mod * dashLengthMod, 0, 0);
}
dashTargetWorldPosition = GetDashArrowTargetByMoveInput(moveInput);
}

// deep math i do not understand
Expand Down

0 comments on commit 6bf9f2a

Please sign in to comment.