Pendulum and Player collision problem

M

MarkyzZz

Guest
Hi. I need some help on solving this one. I've made an ideal pendulum which moves in a semi-circular way . It works fine, but the problem is that when I (or the Player) am on this platform-shaped pendulum, at some moments, i am unable to jump. Sometimes the player just slips into the object and falls down through it.I made the platform to be the child of the GROUND object, that way it should make the collision similar as if the player collided with the ground, with certain exceptions. But it seems i am wrong.

Here's the code:

Platform Step Event
Code:
angle+=(pendulum_frequency*state);
if(angle>180){
    angle=0;
    state=-1;
}
if(angle<-180){
    angle=0;
    state=1;
}
position_x=pendulum_amplitude*sin(degtorad(angle));
position_y=pendulum_amplitude*cos(degtorad(angle));

x= x-position_x;
y= y+position_y;

if(place_meeting(x,y,obj_Player)){
    with(obj_Player){
       
        x= x+obj_Pendulum.position_x;
        y= y+obj_Pendulum.position_x;
    }
}
And here's the code for collision with Walls/Ground in the Player Step Event
Code:
//Collision to the walls
// Vertical
repeat(abs(vsp)) {
    if (!place_meeting(x, y + sign(vsp), obj_Ground))
        y += sign(vsp);
    else {
        vsp = 0;
        break;
    }
}
// Horizontal
repeat(abs(hsp)) {
    // Move up slope
    if (place_meeting(x + sign(hsp), y, obj_Ground) && place_meeting(x + sign(hsp), y - 1, obj_Ground) && !place_meeting(x + sign(hsp), y - 2, obj_Ground))
        y -= 2;
    else if (place_meeting(x + sign(hsp), y, obj_Ground) && !place_meeting(x + sign(hsp), y - 1, obj_Ground))
        --y;
   
    // Move down slope
    if (!place_meeting(x + sign(hsp), y, obj_Ground) && !place_meeting(x + sign(hsp), y + 1, obj_Ground) && !place_meeting(x + sign(hsp), y + 2, obj_Ground) && place_meeting(x + sign(hsp), y + 3, obj_Ground))
        y += 2;
    else if (!place_meeting(x + sign(hsp), y, obj_Ground) && !place_meeting(x + sign(hsp), y + 1, obj_Ground) && place_meeting(x + sign(hsp), y + 2, obj_Ground))
        ++y;

    if (!place_meeting(x + sign(hsp), y, obj_Ground))
        x += sign(hsp);
    else {
        hsp = 0;
        break;
    }
}
 

TheouAegis

Member
Well I think you should try to bug you. Make sure the player is actually trying to jump according to the program. Does the game regard the player in those situations as no longer standing on the ground, and thus unable to jump, or does the game consider the player colliding with the pendulum in such a way that the vertical speed gets cancelled out?
 
B

Becon

Guest
Is it possible that while player is making contact, then player.x and player.y could = pendulum.x and pendulum.y...taking into account thickness of object so you stand on the top of it?
 
M

MarkyzZz

Guest
Well I think you should try to bug you. Make sure the player is actually trying to jump according to the program. Does the game regard the player in those situations as no longer standing on the ground, and thus unable to jump, or does the game consider the player colliding with the pendulum in such a way that the vertical speed gets cancelled out?
Tried it. Seems like the when the pendulum has a specific angle, the player starts overlapping the pendulum's collision mask, and this is why it doesn't allow the jumping.
When the player is moving normally on the platform sometimes he can't jump, i suppose because the vertical speed(vsp) variable keeps changing between 0 and 1 or something like that,meaning that he still falls. So in order to jump, you need to have the vsp = 0,meaning he's on the ground. But still i'm having a hard time to find out how to make him stick on top of that platform.

Is it possible that while player is making contact, then player.x and player.y could = pendulum.x and pendulum.y...taking into account thickness of object so you stand on the top of it?
Well, changing the values in such a way wouldn't even allow me to move on that platform, nor to jump. Or maybe i'm not doing it correctly.
Code:
if(place_meeting(x,y,obj_Player)){
    with(obj_Player){
       
        x= x-obj_Pendulum.position_x;
        y= y-obj_Pendulum.position_x - lengthdir_y(sprite_height/2,0);
    }
}
Anyway, i spotted that the player falls through the pendulum when the angle is between 150->180 , -90 ->-130.
 

TheouAegis

Member
Do you simply handle jumping by checking the jump key and if ground is under the player? If so, try basing it on the player's state or sprite_index or something - anything but the ground. At some point when the player can jump, there is something else you could consider for criterion for jumping.
 
M

MarkyzZz

Guest
Code:
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//React to inputs
move = key_right + key_left;

//Do a jump
if ( place_meeting(x,y+1,obj_Ground)  )
{   
    vsp = key_jump *-jumpspeed;
}
This is how i handle the jumping on the ground. Okay i'll try that.Thanks for the reply.
 
M

MarkyzZz

Guest
Okay i've figured out and fixed the problem. Thank you for the replies guys! Btw, here's the code:
Code:
//Moving Platform in circular
if position_meeting(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,obj_Pendulum)
  {
  my_Pendulum=instance_position(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,obj_Pendulum);
    hsp= obj_Pendulum.position_x;
    vsp = obj_Pendulum.position_y;
    x-=hsp;
   //if(keyboard_check_pressed(vk_space))
    vsp-=key_jump *jumpspeed;
  move_outside_solid(90,sprite_height);
  }
 
Top