SOLVED I need HELP with HITBOXES they won't work

ptrdinis

Member

hey everyone

I tried creating hitboxes for my character but they don't seem to be workink, help would be appreciated

first I created an object called o_hitbox and added a collision to my enemy o_knight and then made the following code



Create event



creator = noone

knockback = 1

damage = 1



Alarm event


instance_destroy()



Then I created a script called create_hitbox with the following code



///@arg x

///@arg y

///@arg creator

///@arg sprite

///@arg knockback

///@arg lifespan

///@arg damage

///@arg xscale

var x_position = argument0

var y_position = argument1;

var creator = argument2;

var sprite = argument3

var knockback = argument4

var lifespan = argument5

var damage = argument6

var xscale = argument7



function create_hitbox(x_position, y_position, creator, sprite, knockback, lifespan, damage, xscale)

{

var hitbox = instance\_create\_layer(x\_position, y\_position, "instances", o\_hitbox)

hitbox.sprite\_index = sprite

hitbox.creator = creator

hitbox.knockback = knockback

hitbox.alarm\[0\] = lifespan

hitbox.damage = damage

hitbox.image\_xscale = xscale

}



Then I just added it to my object o_skeleton in the respective attack states (attack one, attack two, attack three) (because I have a combo workign)



if animation_hit_frame(0)

{

create\_hitbox(x, y, self, s\_skeleton\_attack\_one\_damage, 3, 3, 1, image\_xscale)

}



and the same for the rest of the attacks, trading the sprite for the respective sprite of the attack, example, s_skeleton_attack_two damage


Please help, it's driving me mad!!!
Btw my weapon is already part of my character, its not a pickup
And I already set the correct origin to the needed sprites
 
Before someone comes here and reads off all of the changes to the way scripts work in gms 2.3 I’ll just say that arguments are deprecated and you should be defining them as parameters like this

function create_hitbox(_x,_y,etc);

Anyway, I don’t know if I missed something, but I have a couple of suggestions

1. Are you updating the hitbox’s x and y to be the same as the thing you are applying it to every step

2. Why did you set a collision mask to the night, if you want to check for collision with the hitbox

3. Do the hitbox’s check for when you hit an enemy or when an enemy hits you?
 

ptrdinis

Member
Before someone comes here and reads off all of the changes to the way scripts work in gms 2.3 I’ll just say that arguments are deprecated and you should be defining them as parameters like this

function create_hitbox(_x,_y,etc);

Anyway, I don’t know if I missed something, but I have a couple of suggestions

1. Are you updating the hitbox’s x and y to be the same as the thing you are applying it to every step

2. Why did you set a collision mask to the night, if you want to check for collision with the hitbox

3. Do the hitbox’s check for when you hit an enemy or when an enemy hits you?
hey thank for your time.
to be transparent I'm still a noob at programming so idk how I can answer some of these questions but:
I'm following a tutorial on this and I just wrote down what the guy said and it worked for him,

1. I'm not sure how you do that

2. The thing is that the hitbox doesnt have a collision mask set to it, how would you do it?

3. Right now I'm trying for the hitboxes to check when I hit the enemy, since it didnt work I havent done it the other way around. According to the tutorial I'm following the enemy should dissapear when I attack it but the game just runs like I haven't written any of the code I shared on this thread.
 

FrostyCat

Redemption Seeker
DO NOT start with pre-2.3 tutorials on GMS 2.3+. If you keep using random tutorials on YouTube without discriminating them by GM version, you will keep failing.

Drop whatever you are using now, and instead start with up-to-date GMS 2.3+ tutorials like the ones on this page. Then after you have learned the basics, you can adapt the older material to work.
 
Top