1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 obj.player stuck in wall when duck sprite is activated

Discussion in 'Programming' started by SonicTheHedgehog+123, Feb 14, 2020 at 3:14 PM.

  1. SonicTheHedgehog+123

    SonicTheHedgehog+123 Member

    Joined:
    Feb 9, 2020
    Posts:
    29
    When my player is switching from the normal sprite to the ducking sprite and at the same time is hiting the x axis of the wall he gets stuck. If this happens the player shouldnt be in the wall. He maybe could get a pushback or I could make a invisible wall.
    Here is a picture:

    Screenshot (12).png

    And here is my player duck code:

    if keyboard_check(ord("S"))
    {
    sprite_index = Ducken
    }
    else
    {
    sprite_index = Fledermaus_Bild
    }
    if sprite_index = Ducken
    {
    hspeed = 0
    }


    Does somebody know a good solution for this problem?
    I would be happy for any response:D
     
  2. Weird Dragon

    Weird Dragon Wizard GMC Elder

    Joined:
    Apr 21, 2016
    Posts:
    129
    The reason is probably because the new sprite has a different size, bigger I suppose.
    A pushback as you said could be the solution. So just before the code that changes the sprite you could make the player jump back the amount of pixels that makes the difference in size.

    Also: Please use the code tags when posting code.
     
  3. Kyon

    Kyon Member

    Joined:
    Jun 27, 2016
    Posts:
    510
    Use a mask!
     
  4. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,381
    For sure they have different collision sizes/origins, and that's the cause. One solution is to edit sprites and fix it, better one is to use another sprite as mask, so switching sprites won't affect mask then.
     
  5. Weird Dragon

    Weird Dragon Wizard GMC Elder

    Joined:
    Apr 21, 2016
    Posts:
    129
    Well, I didn't think of a mask when I posted my answer. That is a simple solution where you don't need to think of any extra coding.
     
  6. SonicTheHedgehog+123

    SonicTheHedgehog+123 Member

    Joined:
    Feb 9, 2020
    Posts:
    29
    I did make a smaller collision mask and it works now thank you guys for helping out:p
     

Share This Page