Damage collision not working properly

S

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.
 

Attachments

B

Blaize

Guest
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.
 
S

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.
 

Yal

🐧 *penguin noises*
GMC Elder
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?
 
W

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.
 

Yal

🐧 *penguin noises*
GMC Elder
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.
It looks like this, might be a bit hard to find. Top right corner.
upload_2017-5-7_13-46-41.png
 
S

StanleyG

Guest
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?
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?
 

Yal

🐧 *penguin noises*
GMC Elder
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?
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
 
Top