1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML My enemies are stuck in the ground (SOLVED)

Discussion in 'Programming' started by Vincemon, Oct 17, 2018.

  1. Vincemon

    Vincemon Member

    Joined:
    Sep 8, 2018
    Posts:
    3
    Hello! ;3

    I'm working on a 2D-Platformer and I've created an enemy object. They can be defeated and they could walk from wall to wall. But they don't. When they collide with the ground they turn left and right quickly. And I don't know why.



    This is my code in the Step event:

    vsp = vsp + grv

    //HORIZONTAL COLLISION

    if place_meeting(x+hsp,y,oWall)

    {

    while (!place_meeting(x+sign(hsp),y,oWall))

    {

    x = x + sign(hsp);

    }

    hsp = -hsp

    }

    x = x + hsp;

    //VERTICAL COLLISION

    if place_meeting(x,y+vsp,oWall)

    {

    while (!place_meeting(x,y+sign(vsp),oWall))

    {

    y = y + sign(vsp);

    }

    vsp = 0

    }

    y = y + vsp;

    And in the Create event:

    walksp = 3;

    hsp = walksp;

    vsp = 0;

    grv = 0.4;

    Please help! Why are they stuck and how can I fix this? Please comment if you have any questions. I can send more Information if needed
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    894
    I put all the code you gave in a fresh project and it worked just fine. This means something else is happening. Give the rest of the code for the enemy.
    There is a fair chance it has to do with the sprite's mask.
     
  3. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    115
    try changing the place meeting for horizontal to y-1 chances are your enemy is one pixel inside the ground or so so it detects the floor when looking for walls
     
  4. WillB777

    WillB777 Member

    Joined:
    Jun 25, 2019
    Posts:
    4
    How did you fix this? I am having the same problem. Please help with the enemy stuck in the ground, it's so annoying. nvm i got it.
     
    Last edited: Dec 4, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice