-
Notifications
You must be signed in to change notification settings - Fork 17
fix: reset double jump when impulse up is applied #9510
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
46e2714
reset double jump when impulse up is applied
popuz b05a712
added reset on descending
popuz 97e99c2
small cleanup
popuz 6486aa5
add braces for readability
popuz a48f759
add tests
popuz 5acd00c
removed reset on decending
popuz 8a8fc44
Merge branch 'dev' into fix/movement/double-jump-reset-by-impule
popuz a0c1bd1
cleaned up from cooldown descending reset
popuz 0df8c0e
Merge remote-tracking branch 'origin/fix/movement/double-jump-reset-b…
popuz ff11049
polishing github.qkg1.topments
popuz a553433
removed duplicated Reset
popuz 3e6288d
changed github message logos to more appropriate
popuz d32d7ff
fix 1 nullable lint
popuz ab36f4a
Merge branch 'dev' into fix/movement/double-jump-reset-by-impule
popuz 0b18b87
Merge branch 'dev' into fix/movement/double-jump-reset-by-impule
popuz 99bf0c3
lint fixes
popuz e691374
Merge remote-tracking branch 'origin/fix/movement/double-jump-reset-b…
popuz 48addad
addressed CI security request
popuz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
Explorer/Assets/DCL/Character/CharacterMotion/Tests/ApplyExternalImpulseShould.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| using DCL.CharacterMotion.Components; | ||
| using DCL.CharacterMotion.Settings; | ||
| using NSubstitute; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
|
|
||
| namespace DCL.Character.CharacterMotion.Tests | ||
| { | ||
| public class ApplyExternalImpulseShould | ||
| { | ||
| private ICharacterControllerSettings settings = null!; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| settings = Substitute.For<ICharacterControllerSettings>(); | ||
| settings.CharacterMass.Returns(1f); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ResetJumpCountOnUpwardImpulseWhileGrounded() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = true, | ||
| ExternalImpulse = Vector3.up * 10f, | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2, AirJumpDelay = 0.1f }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(0, jumpState.JumpCount, "An upward impulse launching a grounded character restores jumps"); | ||
| Assert.AreEqual(float.MinValue, jumpState.AirJumpDelay, "A pending air jump is cancelled by the launch"); | ||
| Assert.IsFalse(rigidTransform.IsGrounded, "The launch ungrounds the character"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ResetJumpCountOnUpwardImpulseNearGround() | ||
| { | ||
| // The scene may fire the pad before physics registers a grounded tick, while the character is still | ||
| // within centimeters of the ground. | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = false, | ||
| GroundDistance = 0.3f, | ||
| ExternalImpulse = Vector3.up * 10f, | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(0, jumpState.JumpCount, "An upward impulse close to the ground counts as a landing"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void KeepJumpCountOnUpwardImpulseAwayFromGround() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = false, | ||
| GroundDistance = 10f, | ||
| ExternalImpulse = Vector3.up * 10f, | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(2, jumpState.JumpCount, "An upward impulse clear of the ground is not a landing and does not restore jumps"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ZeroFallingVelocityOnUpwardImpulse() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = false, | ||
| GroundDistance = 10f, | ||
| ExternalImpulse = Vector3.up * 10f, | ||
| GravityVelocity = new Vector3(0f, -20f, 0f), | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(0f, rigidTransform.GravityVelocity.y, "A downward fall must not fight the launch impulse"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ApplyImpulseToExternalVelocityScaledByMass() | ||
| { | ||
| settings.CharacterMass.Returns(2f); | ||
|
|
||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = true, | ||
| ExternalImpulse = new Vector3(0f, 10f, 0f), | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(5f, rigidTransform.ExternalVelocity.y, "Δv = J / m, so a mass of 2 halves the impulse velocity"); | ||
| Assert.AreEqual(Vector3.zero, rigidTransform.ExternalImpulse, "The impulse is consumed after being applied"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void KeepStateOnDownwardImpulse() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = true, | ||
| ExternalImpulse = new Vector3(0f, -10f, 0f), | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(-10f, rigidTransform.ExternalVelocity.y, "A downward impulse is still applied to the velocity"); | ||
| Assert.AreEqual(2, jumpState.JumpCount, "A downward impulse is not a launch and does not restore jumps"); | ||
| Assert.IsTrue(rigidTransform.IsGrounded, "A downward impulse does not unground the character"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void KeepJumpCountOnHorizontalImpulse() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = true, | ||
| ExternalImpulse = Vector3.right * 10f, | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(2, jumpState.JumpCount, "Only an upward impulse counts as a launch"); | ||
| Assert.IsTrue(rigidTransform.IsGrounded, "A horizontal impulse does not unground the character"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void DoNothingOnNegligibleImpulse() | ||
| { | ||
| var rigidTransform = new CharacterRigidTransform | ||
| { | ||
| IsGrounded = false, | ||
| ExternalImpulse = Vector3.zero, | ||
| }; | ||
|
|
||
| var jumpState = new JumpState { JumpCount = 2 }; | ||
|
|
||
| ApplyExternalImpulse.Execute(settings, ref rigidTransform, ref jumpState); | ||
|
|
||
| Assert.AreEqual(2, jumpState.JumpCount, "A negligible impulse leaves the jump state untouched"); | ||
| Assert.AreEqual(Vector3.zero, rigidTransform.ExternalVelocity, "A negligible impulse adds no velocity"); | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
Explorer/Assets/DCL/Character/CharacterMotion/Tests/ApplyExternalImpulseShould.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.