Character's ability to move and interact with the envrionment.
Define a value for h_acceleration and v_acceleration that is common with movement controls.
To be considered solid, the object must have a collision mask and parent of par_solids.
Copy the following code into the Step event:
#region collisions with solids
//stop at horizontal collisions
//smoothly exit overlapping scennarios
if place_meeting(x, y, par_solids) {
//check if hspeed is non zero
if hspeed != 0 {
//Scenario 1: Player is moving into object
//continually increase hspeed until free from instance overlap
//repeat until free from overlap
while place_meeting(x + hspeed, y, par_solids) {
hspeed = (abs(hspeed) + h_acceleration) * - sign(hspeed)
}
}
//executes if hspeed is zero
else if hspeed == 0 {
collision_obj = instance_place(x, y, par_solids)
//Scenario 2: Object is moving into stationary playe
hspeed = collision_obj.hspeed
}
}
//upon predicted collision with a solid, reduce speed
while place_meeting(x + hspeed, y, par_solids) {
//reduce speed to stop at horizontal collision
hspeed = (abs(hspeed) - h_acceleration) * sign(hspeed)
}
//stop at vertical collisions
//upon predicted collision with a solid, reduce speed
while place_meeting(x + hspeed, y + vspeed, par_solids) {
//reduce speed to stop at vertical collision
vspeed = (abs(vspeed) - v_acceleration) * sign(vspeed)
}
#endregion
In the Step event:
//Collisions with water moves the player downward unless on ground
//when colliding with water increase vertical acceleration magnitude
else if place_meeting(x, y, obj_water) {
//accelerates the player downward when interacting with water
vspeed += 2 * v_acceleration
}
else {
// slowly causes the instance to fall
vspeed += v_acceleration
}
If overlapping instance is moving, set character's speed opposite to escape.