GM:S 1.4 Error Making Enemy Move Toward Player!

Discussion in 'Programming' started by JVGameDev, Sep 27, 2016.

  1. JVGameDev

    JVGameDev Member

    Joined:
    Jul 15, 2016
    Posts:
    152
    Hi!


    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object obj_enemy1:

    Variable obj_enemy1.phy_position_x(54, -2147483648) not set before reading it.
    at gml_Object_obj_enemy1_StepNormalEvent_1 (line 2) - phy_position_x += sign(obj_player.x - x);
    ############################################################################################


    This is the error I got, and this is my code


    ///move toward the player
    phy_position_x += sign(obj_player.x - x);
    phy_position_y += sign(obj_player.y - y);

    Please help!
     
    ParodyKnaveBob likes this.
  2. Bingdom

    Bingdom Googledom

    Joined:
    Jul 1, 2016
    Posts:
    1,652
    Is the enemy a physics object? You will only need to use phy_position if the object is a physics object. ;)
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,873
    And if physics is enabled in the room.
     
  4. ParodyKnaveBob

    ParodyKnaveBob theUndiscovered

    Joined:
    Jun 23, 2016
    Posts:
    436
    Seconded and thirded. Also, the manual advises against adjusting the x and y values directly when using the Box2D advanced physics in lieu of adding forces in this and that direction and letting the physics handle it from there.

    Bob $:^ J

    P.S. "Liked" for posting the exact error and relevant code referenced from the error (not to mention describing the problem fine enough in the topic title)!
     
  5. lol

    lol Member

    Joined:
    Jan 2, 2017
    Posts:
    10
    I'm having the same problem as JV GameDev and My room has physics, so does my object
     
  6. lol

    lol Member

    Joined:
    Jan 2, 2017
    Posts:
    10
    Actually using heartbeast tutorial, and for him it works too! Same code, physics enabled in object and room. Please help
     
  7. Ragarnak

    Ragarnak Not Ragnarök Forum Staff Moderator

    Joined:
    Dec 29, 2016
    Posts:
    948
    Aura likes this.
  8. DevNorway

    DevNorway Member

    Joined:
    Jun 26, 2016
    Posts:
    87
    - Enable "physics" in your obj_enemy1 object.
    - Enable "physics" in all rooms used.
     
  9. lol

    lol Member

    Joined:
    Jan 2, 2017
    Posts:
    10
    Thanks, it works now, I actually mispelt 'position' in phy_position_x :)
     

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