Coding Dev Log (Robson): Code Cleanup, Final Fixes, and Parallax Perfected


Robson spent today cleaning up some remaining integration issues and successfully stabilized the most complex bug the team has faced recently: the camera and parallax compatibility conflict. This round of fixes ensures a smoother, more realistic, and more stable core player experience.

Camera and Parallax Compatibility (Resolved)

The primary focus was eliminating the Infinity or NaN values that were being returned in the camera's position vector during the Screen Shake effect.

  • Problem: The initial fix for the camera offset caused the camera's Z position to be set to the player's Z position (which is 0), resulting in a "divide by zero" error within the Parallax script's calculations.
  • Fix: Robson found a solution that maintains player focus while preserving the necessary Z-depth for the parallax. The code now repeatedly sets the camera's X and Y position to the player's current X and Y position, but the crucial Z position is instead set to the camera's Z position before the shake effect started. This allows the parallax script to function correctly while the camera correctly tracks the player's movement, eliminating both the offset and the calculation errors.

Movement and Flipping Refinements (Resolved)

Two subtle but immersion-breaking glitches related to movement and player visuals were also addressed:

  • Resolved: Continuous movement glitch
    • Problem: When the player stopped moving, the character would slide across the floor until hitting an object, as if on ice.
    • Cause: The movement code only set the linear velocity of the player's rigidbody but never explicitly set it back to 0 when input stopped.
    • Fix: A continuous check was implemented. If the player is not currently pressing a horizontal input key (like 'A' or 'D'), the player's horizontal linear velocity is immediately set to 0, ensuring an instant and crisp stop.
  • Resolved: Player flip when pushing glitch
    • Problem: When the player started pushing an object, they would immediately face left, regardless of the direction they were facing when they began the push.
    • Cause: The code responsible for setting the player's scale when not crouching was incorrectly hardcoding the scale to (2, 2, 2). This fixed value overrode the directional logic that uses scale to flip the sprite's orientation.
    • Fix: Robson corrected the code to continuously set the player's scale to (2 * direction, 2, 2) when not crouching. This simple change ensures that the player's direction variable correctly dictates the sprite's facing direction.

Push Square Jump Glitch (Final Resolution)

A secondary issue with the push square and jumping—where the square would gradually drift upwards if the player held the push key while jumping nearby—was also fixed:

  • Problem: Even with the initial restriction on jumping while pushing, the push square still exhibited unintended vertical movement when the player jumped and held the 'P' key. The exact cause was suspected to be a timing or simultaneous issue between frames.
  • Fix: Rather than trying to debug the tricky simultaneous issue, a robust fix was implemented: When the player stops pushing, the push square's Y position is manually set to its original starting Y value. This "reset" ensures that the object is always grounded and ready for the next interaction, regardless of any minute vertical displacement caused by nearby player actions.

Leave a comment

Log in with itch.io to leave a comment.