A
AtomicBlade
Guest
I tried to make some code for a slime moving randomly. It all worked fine, until I decided to change the sprite index based off of where it was during the jump. Eg, an animation just before the jump, an animation as it falls, etc. Unfortunately, after adding in the code, the slime stopped jumping, instead hanging in the air at sprite index 7. I identified the code that caused this and removed it, only for the slime to just run through its animation like normal, despite the code, and it still refused to jump. I'd like to know how to make the slime jump again, as well as how to change the other line of code so that it works as intended.
Code:
vsp = vsp + grv;
//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = -hsp * 0.8;
}
if(canmove) x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
if(alarm[0] < 1) alarm[0] = random_range(fps*0.5,fps*4);
canmove = false;
} else canmove = true;
y = y + vsp;
//Jumping Animation
if (!jumping) {
if(image_index > 2) image_index = 0;
}
if (jumping){
if (place_meeting(x,y+vsp,oWall)) {
if (landing = false) {
if(image_index > 4) {
hsp = random_range(-4,4)
vsp = random_range(-7,-10);
}
}
if(landing) {
image_speed = 1;
if (image_index = image_number-1) {
landing = false;
jumping = false;
}
}
}
if (!place_meeting(x,y+vsp,oWall)) {
image_speed = 1;
if (vsp < -0.5) {
if(image_index > 6) {
image_speed = 0;
image_index = 7;
}
}
if(vsp > -0.5) && (vsp < 0.5) image_index = 7; This is the line that caused the first issue.
if(vsp > 0.5) {
image_speed = 1;
if (image_index > 10) {
image_speed = 0;
image_index = 10;
landing = true;
}
}
}
}
Code:
vsp = vsp + grv;
//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = -hsp * 0.8;
}
if(canmove) x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
if(alarm[0] < 1) alarm[0] = random_range(fps*0.5,fps*4);
canmove = false;
} else canmove = true;
y = y + vsp;
//Jumping Animation
if (!jumping) {
if(image_index > 2) image_index = 0;
}
if (jumping){
if (place_meeting(x,y+vsp,oWall)) {
if (landing = false) {
if(image_index > 4) {
hsp = random_range(-4,4)
vsp = random_range(-7,-10);
}
}
if(landing) {
image_speed = 1;
if (image_index = image_number-1) {
landing = false;
jumping = false;
}
}
}
if (!place_meeting(x,y+vsp,oWall)) {
image_speed = 1;
if (vsp < -0.5) {
if(image_index > 6) {
image_speed = 0;
image_index = 7;
}
}
if(vsp > -0.5) && (vsp < 0.5) image_index = 7; This is the line that caused the first issue.
if(vsp > 0.5) {
image_speed = 1;
if (image_index > 10) {
image_speed = 0;
image_index = 10;
landing = true;
}
}
}
}