You are not logged in.
Pages: 1
Hmm, no suggestions after all this time...? It's like a ghost town around here!!
In any case, I finally got a solution for this one so I'll update here. Replace the red code in the above post as follows:
if (place_free(x+hspeed,y)){}
else
hspeed=0;
I'm using some code which allows my character to be knocked back after jumping on top of a spike. So far this works, but I'm encountering a problem whereby my character will continue to move into any nearby wall objects once the effect begins. I know that place_free is normally used to correct this, but the wall clipping glitch still occurs. I've highlighted this additional code in red. Can anyone help me out?
Many thanks.
//Spike Knockback
if place_meeting (x,y+10,obj_spike)
{
if other.x > x
hspeed = -4
else
hspeed = 4
vspeed = -4
}
if abs(hspeed) > .5
hspeed *= .8
else
hspeed = 0
if place_free(x+hspeed,y)
{
if abs(hspeed) > .5
hspeed *= .8
else
hspeed = 0
}
Ok, I got some help on this one from a different source, so I'll update the thread, here.
It turns out that image_xscale = -1, during a left turn, was causing the collision with wall instances when applied to ladder climbing. Here's the code with image_xscale:
//Move left and right
if (Key_Left)
{
hsp = -6;
image_xscale = -1;
}
if (Key_Right)
{
hsp = 6;
image_xscale = 1;
}
As such, I needed to set image_xscale to 1 when on the ladder - highlighted in red:
//Ladder
if (Key_Up || Key_Down)
{
if place_meeting(x,y,par_ladder) ladder = true;
}
if (ladder)
{
if (Key_Up && (Key_Right || Key_Left || Key_Jump)) || !place_meeting(x,y,par_ladder)
ladder = false;
else
{
vsp = 0;
hsp = 0;
image_xscale = 1
if (Key_Up) vsp = -2;
if (Key_Down) vsp = 2;
if !place_meeting(x,y,par_ladder) ladder = false;
if (Key_Up && (Key_Right || Key_Left || Key_Jump)) ladder = false;
if (Key_Jump) ladder = false;
if (Key_Right) ladder = false;
if (Key_Left) ladder = false;
//Centre Sprite on Ladder
closest_ladder = instance_nearest(x,y,par_ladder)
x = closest_ladder.x+(closest_ladder.sprite_width/2);
}
}
Hope this helps anyone who encounters the same problem. Good luck.
Hello, this is my 1st time posting!! I have a problem that will require a bit of explaining, so please bear with me.
Basically, I'm putting together a game similar in style to 'Thomas Was Alone' &, as such, my character sprite, wall and ladder instances are all 32x32 squares. Below are the parts of my code for climbing a ladder and detecting horizontal & vertical collisions.
When I tested the code initially, the character would get stuck on ladders next to walls when facing to the left. I then added the code, highlighted in blue, at the beginning of the vertical collision script and this corrected the problem. Unfortunately, it then created a new problem wherein the character will continue climbing down into the floor or up into the ceiling if down or up are held, respectively.
I was told that I need to use some code that will check when the sprite has reached the floor or ceiling, rather than check for a collision. As I'm new to coding (most of what you see here is from online tutorials), I'm at a loss as to how to go about doing this. The code in red was the closest I've gotten, however it just brings me back to my original problem of getting stuck on the ladder. Can anyone please help me out?
Many thanks.
//Ladder
if (Key_Up || Key_Down)
{
if place_meeting(x,y,par_ladder) ladder = true;
}
if (ladder)
{
if (Key_Up && (Key_Right || Key_Left || Key_Jump)) || !place_meeting(x,y,par_ladder)
ladder = false;
else
{
vsp = 0;
hsp = 0;
if (Key_Up) vsp = -2;
if (Key_Down) vsp = 2;
if !place_meeting(x,y,par_ladder) ladder = false;
if (Key_Up && (Key_Right || Key_Left || Key_Jump)) ladder = false;
if (Key_Jump) ladder = false;
if (Key_Right) ladder = false;
if (Key_Left) ladder = false;
//Centre Sprite on Ladder
closest_ladder = instance_nearest(x,y,par_ladder)
x = closest_ladder.x+(closest_ladder.sprite_width/2);
}
}
//Horizontal Collision
if place_meeting(x+hsp,y,par_wall)
{
while (!place_meeting(x+sign(hsp),y,par_wall)) x+=sign(hsp);
hsp = 0;
}
x += hsp;
//Vertical Collision
if !(ladder);
else
{var inst;
inst = instance_place(x, y, par_wall)
if inst != noone
{grounded = 1
}
}
if place_meeting(x,y+vsp,par_wall)
{
while (!place_meeting(x,y+sign(vsp),par_wall)) y+=sign(vsp);
if (sign(vsp) == 1)
{
grounded = 1;
djump = 1;
}
vsp = 0;
}
else
{
grounded = 0;
}
y += vsp;
Pages: 1