S
SoMalFra
Guest
I've been trying to do an Animation code for the player that works with my current movement code. It's kind of a mess at the moment, so i've decided to try a new one instead of trying to fix it, because it would probably take way too much effort, that could be evaded doing something new. The code at the moment has some bugs I just can't find a way to fix. As an example, if i'm touching a wall and press a button to look to the other side, it just instantly snaps me to a wall on the opposite way. If there's no wall there, the game just totally freezes, and i can't even close it the normal way. The code i'm using currently is the following:
Script "Move"
Step event object "oPlayer" (the movement part)
Code:
step event object "oPlayer" (the animation part)
Create event (oPlayer)
If ANYTHING else is needed, just ask me and i'll post. Thank you very much.
Script "Move"
GML:
///Script "move"
var speed_ = argument0;
var bounce_ = argument1;
if place_meeting(x+speed_[h], y, oWall) {
while !place_meeting(x+sign(speed_[h]), y, oWall) {
x += sign(speed_[h]);
}
if bounce_ > 0 {
speed_[@ h] = -speed_[@ h]*bounce_;
} else {
speed_[@ h] = 0;
}
}
x += speed_[h];
if place_meeting(x, y+speed_[v], oWall) {
while !place_meeting(x, y+sign(speed_[v]), oWall) {
y += sign(speed_[v]);
}
if bounce_ > 0 {
speed_[@ v] = -speed_[@ v]*bounce_;
} else {
speed_[@ v] = 0;
}
[CODE]move(speed_, nothing);
var hinput = keyboard_check(vk_right) - keyboard_check(vk_left);
if hinput != 0 {
speed_[h] += hinput*acceleration_;
speed_[h] = clamp(speed_[h], -max_speed_, max_speed_);
} else {
speed_[h] = lerp(speed_[h], 0, friction_);
;
}
if !place_meeting(x, y+1, oWall) {
speed_[v] += grv;
}
y += speed_[v];
}
Step event object "oPlayer" (the movement part)
Code:
Code:
move(speed_, nothing);
var hinput = keyboard_check(vk_right) - keyboard_check(vk_left);
if hinput != 0 {
speed_[h] += hinput*acceleration_;
speed_[h] = clamp(speed_[h], -max_speed_, max_speed_);
} else {
speed_[h] = lerp(speed_[h], 0, friction_);
;
}
if !place_meeting(x, y+1, oWall) {
speed_[v] += grv;
}
step event object "oPlayer" (the animation part)
if (!place_meeting(x,y+1, oWall))
{
sprite_index = sPlayerA;
image_speed = 0;
if (sign(speed_[h]) > 0) image_index = 1; else image_index = 0
}
else
{
image_speed = 0.1;
if (speed_[h] == 0)
{
sprite_index = sPlayer;
image_speed = 0.05
}
else
{
sprite_index = sPlayerR;
}
}
if (speed_[h] != 0) image_xscale = sign(speed_[h]);
if key_down
{
sprite_index = sPlayerD
}
if key_up
{
sprite_index = sPlayerU
}
Create event (oPlayer)
Code:
speed_ = [0,0]
grv = 0.25;
jumpsMax = 2
jumps = 2
jumpspeed_normal = 3.5;
jumpSpeed = jumpspeed_normal
firingdelay = 0;
max_speed_ = 1.5;
nothing = 0
acceleration_ = .3;
friction_ = .3
If ANYTHING else is needed, just ask me and i'll post. Thank you very much.