Module 1
Platformer Basics
From “Gamer to Games Creator”
Student Workbook
MODULE 1
LESSON 2 - WALL
COLLISION
DETECTION
WHO IS THIS FOR?
FOR ALL GAME
CREATORS
WHY THIS MATTERS
PLATFORM
GET THE ER
FUNDAMENTALS OF BASICS
YOUR PLATFORMER
SET UP
MODULE LESSONS
01 GRAVITY, MOVEMENT & COLLISIONS
02 WALL COLLISION DETECTION
03 VARIABLE CONSTANTS
WE ARE
HERE
LESSON 2
Wall Collision Detection
Introduction
In the last lesson we scripted the standard method of detecting and
fixing floor collisions. We now want to do the same for wall
collisions, but... perhaps there is a better way... Instead of moving the
player in large steps and backing out of collisions slowly, in this
lesson we will switch to moving in small steps until we collide. This
change will open up some great advantages later on as we enhance
our platformer and look to handling slopes and ledges!
Then, with full collision
detection in place we’ll be
able to fix our flying bug by
only allow the player to jump
after making contact with
the ground. We’ll use the
“Coyote Jump” method that
gives a little extra time to
jump even after running off a
ledge.
? WHAT IS A “COYOTE JUMP”?
A "Coyote Time" or "Coyote Jump" allows a player to jump
even after having left a platform or ledge and is named
after Wile E. Coyote from the "Looney Tunes" cartoons!
This helps in fast-paced games where precision timing is
crucial and addresses the common frustration of pressing
the jump button just a fraction of a second too late.
Although this mechanic is not visible to the player it
significantly affects the gameplay feel, enhancing the
player's sense of control for improved playability.
2024 Griffpatch
Latest “Script” Development
“The Coyote Jump” - the variable “falling” records
how long the player has been falling for. We allow
them to jump only if they were very recently
touching the ground (<3 frames ago).
These blocks were replaced by
the new “Move - in steps“ block
? WHAT IS THE “ABS” BLOCK?
The "abs" block (short for absolute) is a maths operator
that turns any number into its positive version!
So both the “abs of -4 = 4” and the “abs of 4 = 4”.
2024 Griffpatch
The new “Move - in steps“ block.
Make sure it is set to Run Without Screen Refresh!
Rather that moving in large steps and then slowly backing
out of a collision, we will now always move in small steps
until we collide. This opens up some great advantages later
on as we enhance our platformer!
The diagram to the right shows a single speed y of “-4" split
into 4 small steps.
Every game frame, we add one to ‘falling’ (but we’ll set
this back to 0 when we touch the ground)
We break the player’s larger movement up into small x & y steps
Record the last x position in case we collide...
Small step in x direction
Move by one step of “speed x”
If we collide then;
Set the player back to the last safe x position
and set their walking speed (x) to 0.
Record the last y position in case we collide...
Move by one step of “speed y”
Small step in y direction
If we collide then;
Set the player back to the last safe y position
If speed y < 0 (travelling down into the
collision), then set falling to 0 as we are on
the ground
finally, set their falling speed (y) to 0.
Now repeat for the remainder of the small steps
2024 Griffpatch
Conclusion
In this lesson we've explore how to view things from another
perspective since there's often different approaches we can take to
coding something up... And some are better than others.
Well done!
You now know how to code up “The Coyote Jump”
In our next lesson we'll explore making your
character movements much more realistic as
we have fun messing around with physics!
Platformer Mod 1 Lesson 1
2024 Griffpatch