Jump to content


Photo

Very buggy ladders & gravity


  • Please log in to reply
3 replies to this topic

#1 Trollbucket

Trollbucket

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 27 June 2012 - 10:45 AM

My issues are:
  • If I keep pressing the up key, the player keeps floating up into the air even when there's no ladder. Posted Image
  • Sometimes the player won't hit the ground entirely when floating down off a platform (gravity) Posted Image
  • If I let go of the up key when I get to the top of a ladder, sometimes gravity will then pull the player back down.

Thanks.

Here's the information from my events:

Step Event:

COMMENT: Run code to check and set gravity.
execute code:

// Check if there's no solid collision 1 pixel under the player
if place_free(x, y + 32)
{ 
    // Check if the object is a collision with the ladder (not solid)
    if place_meeting(x, y, objLadder)
        // Another check if there's a ladder under the player
        || place_meeting(x, y + 32, objLadder)
        {
        // Do nothing
        
    }
    // If there is no collisions...
    else
    {
        // Set gravity direction to down...
        gravity_direction = 270 
        // ... and speed to 1
        gravity = 1.0 
    }
}
// If there is a collision...
else
{
    // Set the gravity direction...
    gravity_direction = 270
    // ... and speed to 0 (no gravity)
    gravity = 0 
}

COMMENT: Set the sprite speed to 0.3.
execute code:

// Set the image speed to 0.3
image_speed = 0.3

COMMENT: Run code to check if the player is on a ladder or not.
execute code:

if place_meeting(x, y, objLadder) {
    on_ladder = true;
} else {
    on_ladder = false;
}

Collision Event with object objLadder:

COMMENT: Change sprite to back.
set the sprite to spriteBack with subimage 0 and speed 1
COMMENT: Is the up key pressed?
if expression keyboard_check_pressed(vk_up) is true
      COMMENT: Move up the ladder
      start moving in directions 000000010 with speed set to 4

Key Press Event for Key: (up)

COMMENT: Do ladder checking and jump
execute code:

// Checks if theres a ladder under the character
if (position_meeting(x, y, objLadder)) {
      // If so, add a behavior that tells the player that he is climbing a ladder
      on_ladder = true;
}
// If not, jump
else {
    if !place_free(x, y + 1) { // If you're on the ground
        vspeed = -6 // Do the jump
    }
}


  • 0

#2 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8

Posted 27 June 2012 - 01:30 PM

for the floating up issue you can make a invisible object that the player collides
with to cause 0 gravity and that will keep the player level from the point he hits the object.

for not hitting the ground you need to find a better collsion script or if you ground
has a mask make sure its not taller then the grounds actual sprite.

for the gravity pull down the player its because you need to make the gravity = 0
once you start pressing the key to go up.


i did not read the code yet but if i decide to i will post the code fixes....but im not great
in collision scripts.
  • 0

#3 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8

Posted 27 June 2012 - 01:38 PM

*wish this was the actual code it looks like snippets to prevent copying :D*


found the fix for the floating.


// Check if there's no solid collision 1 pixel under the player
if place_free(x, y + 32)
{
// Check if the object is a collision with the ladder (not solid)
if place_meeting(x, y, objLadder)
// Another check if there's a ladder under the player
|| place_meeting(x, y + 32, objLadder)
{
// Do nothing

}


change if place_free(x, y + 32)

to

if place_free(x, y + 1)


you might have to raise the 1 a bit and this may not work but its floating because if there is something below the player from 0 pixels to 32 pixels then the gravity will stop.



edit* once again change the 32 lower like 1 or so

|| place_meeting(x, y + 32, objLadder)


edit 2 * this should fix the falling on the ladder

if expression keyboard_check_pressed(vk_up) is true
COMMENT: Move up the ladder
start moving in directions 000000010 with speed set to 4


change it to

if expression keyboard_check_pressed(vk_up) is true{
COMMENT: Move up the ladder
start moving in directions 000000010 with speed set to 4}

Edited by robinsblade, 27 June 2012 - 01:43 PM.

  • 0

#4 Trollbucket

Trollbucket

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 27 June 2012 - 09:05 PM

edit 2 * this should fix the falling on the ladder

if expression keyboard_check_pressed(vk_up) is true
COMMENT: Move up the ladder
start moving in directions 000000010 with speed set to 4


change it to

if expression keyboard_check_pressed(vk_up) is true{
COMMENT: Move up the ladder
start moving in directions 000000010 with speed set to 4}

Ok, the floating is fixed, now the player still drops down the ladder if I don't move across in time, and this seems the same?
I had +32 because there's 32px of blank space above my sprites, and the origin is in the top left, so I figured I should have made it go to the actual sprite, but it seems this isn't the case. I also fixed the gravity issue last night.

Thanks.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users