Physics and Engine
9 years ago
French Southern Territories

Another Perspective (AP) is a game made in GameMaker:Studio. The instance known as "player" is called Player and is stored into Objects > Entities > Player > Player. I'll try to focus only on movments variables and not on other variables so the code isn't entirely here. This object has 6 events : Create : Initialisating a few variables, in particular the followings : //Player Settings i_walksp=4.7; //Walking speed (pixels per frame) i_jumpsp=-8; //Jumping speed (negative because it goes up) i_grav=0.42; //Gravity strength (usually a small value)

walksp = i_walksp ¤ sign(image_yscale); jumpsp = i_jumpsp ¤ sign(image_yscale); grav = i_grav ¤ sign(image_yscale);

// On Spawn

hsp=0; //Horizontal speed vsp=0; //Vertical speed grounded=1; //Whether the player is on the ground PlayerControl=true //Give the player control

boost = 0; jumpfree = 0; bufferjump = 0;

A Alarm[0] and Outside rooms events that are related to out of bounds but nothing important. A Draw event to draw the character. A Room Start that saves the game. Everytime the room changes, the player is destroyed and created on the next room. When you go out of bounds (die) the map restarts (same script as before is executed). That leads us to the main "Step" Loop. (My TAS Tool override this Step event with a "Begin Step" event that happens before the Step Loop) Let's analyse actions on the Step Loop step-by-step (in order):

if (!Freeze) { image_speed = 0.2; walksp = i_walksp ¤ sign(image_yscale); jumpsp = i_jumpsp ¤ sign(image_yscale); grav = i_grav ¤ sign(image_yscale); This means if the player isn't stuck (from a restart or something), the variable walksp equals i_walksp. jumpsp equals i_jumpsp. ¤ sign(image_yscale) means the force is applied to the direction facing the player. grav equals i_grav. This part isn't that important is dedicated to the part where you calculate the variables for movement, you don't calculate it in-depth, you don't apply the movement yet. Not calculate it. This means what happen in the end of this step at frame N is applied at frame N+1, not frame N. I will not forget to mention that you are ejected if you can't clip in a block deeply enough because you get pushed during a frame (but it's kinda boring in-depth).

//Left & Right Move Confirm x += hsp; X movements is applied to X axis of the player's sprite

if (scr_tilecollide(x,y+image_yscale)) || (place_meeting(round(x),round(y+image_yscale),obj_collision_parent)) { if (grounded = 0) sound_play(snd_foot1); grounded=1; } else { grounded=0; } If the Player meets the instance the "family" or parent of objects "obj_collision_parent" the variable grounded is set to 1. Else 0.

y += vsp; means that you apply the y axis movement to the y axis player sprite coordinates.

About strafing :

// Left & Right Input Check if (Key_Right) { hsp=(walksp ¤ sign(image_yscale)) ¤ (1+boost); if sign(image_xscale) !=1 image_xscale¤=-1 } if (Key_Left) { hsp=(-walksp ¤ sign(image_yscale)) ¤ (1+boost); if sign(image_xscale) !=-1 image_xscale¤=-1 }

if (!Key_Right and !Key_Left) { hsp=0; }

The horizontal speed is set to the walksp times the boost + 1. The force is applied facing the player.

Now, let's talk about jumping. This is kinda hard to explain, you'll need to read the code to understand it :

if (Key_Jump) { bufferjump = 16; }

if (bufferjump > 0) { if (jumpfree > 0) { jumpfree = 0; grounded = 0; vsp = jumpsp; bufferjump = 0; if (boost < 0.2) boost+= 0.1 } else { bufferjump -=1; } }

//Add Gravity if (!grounded) { vsp += grav; } else { if (bufferjump == 0) boost = 0; }

This code explains in-depth how the physics is calculated for jumping. I assume bufferjump is for the time you have a buffer for jumping. Jumpfree positive means that you can jump after a "Soulchange" (it's on other parts of the code and kinda boring).

And it's done.

I hope you liked it. These are the main datas/functions/variables for the player movement in Another Perspective.

Статистика игры
Подписчики
41
Времена
442
Игроки
74
Последние запуски
Последние темы
Опубликовано 9 years ago
games:thread_reply_count
Опубликовано 3 years ago
games:thread_reply_count
Опубликовано 3 years ago
games:thread_reply_count
Опубликовано 6 years ago
games:thread_reply_count
Опубликовано 6 years ago
1 ответ
Опубликовано 9 years ago
games:thread_reply_count