Damage collision not working properly

Discussion in 'Programming' started by StanleyG, May 7, 2017.

  1. StanleyG

    StanleyG Guest

    Hello,

    Im making a kinda basic side scrolling platformer, where you can also attack enemies and stuff.
    But I have a weird problem, this is my code (see image) for attacking. Basically whenever I press attack key, it creates an object next to my character which dissapears after few moments, the object_attack has collision with object_monster and inside that collision is code other.hp-=1. Object_attack is set to "sensor".
    But for some reason if I stand next to object_monster and attack it while we are standing both still, it does nothing. It only damages/kills it if its moving while colliding with object_attack. That also goes vice versa, when object_monster attacks me while im standing still and its also standing still, it doesnt damage me.
    Any workaround around this? I have no idea what to do.

    Thank you for your time.
     

    Attached Files:

  2. Blaize

    Blaize Member

    Joined:
    Jul 27, 2016
    Posts:
    63
    I haven't really worked with physics in GMS before so you'll have to give me some leeway here.
    From what I see there, is that you're creating the instance at x,y - that is, you're creating the melee box at your player object's origin. You need to give it an offset.
     
  3. StanleyG

    StanleyG Guest

    Im creating it at x,y because the damage object has kinda weird origin, but I tried to change it to phy_position_x and phy_position_y and it had no effect. When the player is facing left the code is phy_position_x-40 and it still only works while moving.
    I tried to set density of the attack object higher than zero, it worked then even while standing still but the damage_object was falling down and it didnt look very good.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,556
    Have you tried giving the attack object horizontal velocity based on the direction the player is facing? Is there a reason for the attack to be a physics object, non-physics objects are usually easier to control?
     
  5. Waneeta

    Waneeta Guest

    Hi, sorry this is off topic: i'm a brand new forum member and i'm trying to figure out how to make a forum thread as I really need help - but i can't see a 'make new thread' button anywhere? I've subscribed and confirmed my email address. Thanks for any help.
     
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,556
    It looks like this, might be a bit hard to find. Top right corner.
    upload_2017-5-7_13-46-41.png
     
  7. Waneeta

    Waneeta Guest

    Oh thank you so much.
     
  8. StanleyG

    StanleyG Guest

    Well Its physics object because everything is physics based and I dont want to rebuild it from the beggining. And your velocity suggestion works, thanks for that, but can anybody explain why it doesnt work without it?
     
  9. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,556
    Physics and non-physics objects can still interact just fine, you only need physics for stuff that has physics :p

    And because you spawn the object in the middle of the player, you want the attack to move out from the player in the direction you're attacking...
    upload_2017-5-8_13-57-1.png
     
    StanleyG likes this.

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