T
Thanos
Guest
Hello, I've been struggling with a collision problem.
I've got an obstacle object that moves at a negative hspeed towards the player. When the player collides with it the player also moves at that negative hspeed and if you use the jump key the player can jump to overcome the obstacles.
My real problem is that if the player object collides with the obstacle and the user presses the jump key while the player is in mid-air the player jumps again. Theoretically the solution is simple for this one but i can't seem to get it.
I tried statements like this without result :
Here's the code for the jumpkey which doesn't work correctly:
Here is the collision:
The Object_obstacles is a parent object that includes these 3 objects in the image:
If anyone can help i'd be much obliged.
I've got an obstacle object that moves at a negative hspeed towards the player. When the player collides with it the player also moves at that negative hspeed and if you use the jump key the player can jump to overcome the obstacles.
My real problem is that if the player object collides with the obstacle and the user presses the jump key while the player is in mid-air the player jumps again. Theoretically the solution is simple for this one but i can't seem to get it.
I tried statements like this without result :
Code:
if place_meeting(x, y + 1, obj_jumpable) && keyboard_check_pressed(jump_key) {
// JUMP CODE HERE
}
Code:
if(keyboard_check_pressed(ord(global.up)) && place_meeting(x,y+1,Object_obstacles))
{
sprite_index=Running
image_speed=0.10
vspd=-jumpspd
}
Code:
if(place_meeting(x+hspd,y,ground)|| place_meeting(x+hspd,y,Object_obstacles))
{
while(!place_meeting(x+sign(hspd),y,ground) && !place_meeting(x+sign(hspd),y,Object_obstacles))
{
x+=sign(hspd)
}
hspd=ground.hspeed
}
x+=hspd
if(place_meeting(x,y+vspd,ground) || place_meeting(x,y+vspd,Object_obstacles))
{
while(!place_meeting(x,y+sign(vspd),ground) && !place_meeting(x,y+sign(vspd),Object_obstacles))
{
y+=sign(vspd)
}
vspd=0
}
y+=vspd
If anyone can help i'd be much obliged.
Attachments
-
7.7 KB Views: 7
Last edited by a moderator: