Scan a list
Follow a for loop that examines collision contacts and stops at the first upward-facing normal.
On this page
A collision can contain several contact points. PlayerMotor.UpdateGrounded scans them until one normal points up past the grounding threshold.
The problem
Section titled “The problem”Using only the first contact can miss the floor when the player touches a corner. The motor must inspect each contact, but it can stop as soon as one proves the player is grounded.
When to reach for it
Section titled “When to reach for it”- A collection must be inspected one item at a time.
- Finding the first match is enough.
- Work can stop as soon as that match appears.
See it
Section titled “See it”
-
Open
PlayerMotor.UpdateGroundedin Graph View. -
Read the for-loop controls:
istarts at zero, continues while it is less thancollision.contactCount, and increments once per pass. -
Inside the loop, follow
iintocollision.GetContact(i), then read the contact’snormal.yvalue. -
Follow the branch that compares
normal.ywithGroundNormalThreshold. -
Follow the true path. It sets
_groundedtotrue, then returns before another contact is read. -
Follow the false path back to the loop. The next contact is checked until one passes or the collection is exhausted.
What it writes
Section titled “What it writes”The current Platformer method is:
The return ends the method immediately. If no contact passes the threshold, the loop completes without setting _grounded.
When it goes wrong
Section titled “When it goes wrong”When it goes wrong
| Symptom | Check | Fix |
|---|---|---|
| Only the first contact is checked. | Follow the loop condition and iterator back edge. | Keep GetContact inside the loop and feed it the current i value. |
| A wall contact marks the player grounded. | Read the comparison against GroundNormalThreshold. | Keep the upward-normal threshold on the true path before setting _grounded. |
| Contacts continue to be checked after ground is found. | Trace execution after the _grounded assignment. | Connect the return directly after setting _grounded. |
- Loops: read initializer, condition, iterator, and body.
- Return and throw: follow the early exit from the loop body.
- Get and set: follow the write to
_grounded.