• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need help with Hitboxes!

D

Doooooli

Guest
So I have a simple script that checks if obj_enemy_slime is nearby my punches, and if it is it will take damage, so it's working! But it's not as good as I want it to be, so I watched some vids/read some guides, and found out about hitboxes! So I made an obj_damge, and that has an collision event with obj_enemy_slime so the slime is suppose to loose hp each time it collides with it! But I've run into some problem!

You see this is my first and active punching script:

Code:
pup = base_pup + global.strength / 5;

pxg = base_pxg + global.strength / 5;

if (keyboard_check(ord('C'))) or (gamepad_button_value(4, gp_shoulderrb)) and can_attack
{ 
   instance_create(x,y,obj_damage);
   global.punchingskillxp += pxg;
   var enemy = instance_place(x-64,y-64,obj_enemy_slime);
   audio_play_sound(snd_punchsound,10,false);
   can_attack = false;
   alarm[0] = room_speed;
if (enemy!=noone)
{
    with enemy { hp -= other.pup; }
    }   
}
(the pup and pxg is local variables for the player)
So as you can see the hp the slime is loosing is pup! and pup (punching power) is suppose to be increased by how much strength my character has(and it does) but I can't figure out how to get it to work with my hitboxes! This is the collision script inside the obj_damage:
Code:
other.hp -= other.pup;
But it doesn't work because obj_damage doesn't have pup :/

How am I suppose to fix this? If you need further explanation, I'll be happy to apply

thx
 
C

CedSharp

Guest
When you create an instance of your obj_damange object, you can save the id of the player in the object like this:
Code:
var damage = instance_create( ... obj_damage );
damage.source = id;
And then when your obj_slime collision event with obj_damage, you can do this:
Code:
hp -= other.source.pup;
this should get you on the right track :p
 
D

Doooooli

Guest
When you create an instance of your obj_damange object, you can save the id of the player in the object like this:
Code:
var damage = instance_create( ... obj_damage );
damage.source = id;
And then when your obj_slime collision event with obj_damage, you can do this:
Code:
hp -= other.source.pup;
this should get you on the right track :p
Can't get it to work :/

Got this error:


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Eventobj_enemy_slime
for object obj_damage:

Variable <unknown_object>.<unknown variable>(100020, -2147483648) not set before reading it.
at gml_Object_obj_damage_CollisionEvent_11_1 (line 1) - other.hp -= other.source.pup;
############################################################################################

My script:

Code:
if (keyboard_check(ord('C'))) or (gamepad_button_value(4, gp_shoulderrb)) and can_attack
{ 
   var damage = instance_create(x,y,obj_damage);
   damage.source = id;
   global.punchingskillxp += pxg;
  audio_play_sound(snd_punchsound,10,false);
   can_attack = false;
   alarm[0] = room_speed;
}
and

Code:
other.hp -= other.source.pup;
why is dat? :) (I'm not good at reading error codes :p)

Or maybe I'm suppose to put that var damage inside the obj_damage create event? xD
 
C

CedSharp

Guest
If you put the code in obj_damage, it won't work.
If you want to place the code in the collision event of obj_damage with obj_enemy_slime, then this is what you want:
Code:
other.hp -= source.pup;
In a collision event, 'other' refers to the "other" instance with who you are colliding.
so if you are in the object obj_damage, and you execute something in the collision with obj_enemy_slime object,
then 'other' is equal to the obj_enemy_slime you are colliding with :p
 
D

Doooooli

Guest
If you put the code in obj_damage, it won't work.
If you want to place the code in the collision event of obj_damage with obj_enemy_slime, then this is what you want:
Code:
other.hp -= source.pup;
In a collision event, 'other' refers to the "other" instance with who you are colliding.
so if you are in the object obj_damage, and you execute something in the collision with obj_enemy_slime object,
then 'other' is equal to the obj_enemy_slime you are colliding with :p
THANK YOU! :D
 
Top