In a single-object method, instead of having actual hidden collider objects you simulate them instead. Let's say you have a simple 20*20 pixel hitbox which for targeting purposes needs to be divided into upper and lower halves. You'd store into variables the x/y positions of every hit area, here being 0,0 to 20,10 for the upper half and 0,10 to 20,20 for the lower half. When a collision is registered, you loop through these boxes and check whether the colliding hitbox overlaps with these. First you compare the target's and collider's positions and calculate the relative position of the collider's hitbox. Overlap check would then be a rectangle-in-rectangle check, you could even use point check if it is a single-pixel bullet hitbox. Note that sprite origins affect these since it determines where the 0,0 origin point is inside the hitbox.BTW what functions are best for the other method? I don't even know where to start for that.
if collision_rectangle(x+0,y+0,x+50,y+25,obj_Bullet,true,true){
draw_sprite(spr_Hit_BOX,0,x,y+200);
}
if point_in_rectangle(obj_Bullet.x,obj_Bullet.y,x+0,y+0,x+50,y+25){
draw_sprite(spr_Hit_BOX,0,x,y+200);
}
function place_meeting_ext(_x, _y, _obj, _mask, _xsc, _ysc, _ang){
// Remember these for later
var xx = x, yy = y, msk = mask_index, xsc = image_xscale, ysc = image_yscale, ang = image_angle;
// Move to position and apply fields
x = _x; y = _y; image_xscale = _xsc; image_yscale = _ysc; image_angle = _ang;
// This is the bread and butter. Try not to stand up too fast!
var _r = place_meeting(x,y,_obj);
// Move everything back
x = xx; y = yy; mask_index = msk; image_xscale = xsc; image_yscale = ysc; image_angle = ang;
return _r;
}
There is nothing wrong with doing object based collisions....in many cases its easier to handle, and unless you have way too many, the performance is not an issue either.Yeah I've given it some thought, and I think I might just use object based collision rather than complex scripting. It should make it easier to have enemies that can have specific limbs targeted (like individual arms/legs) but thanks for the suggestions.
BTW I don't understand anything you just posted. Why is "function" written at the start? And does it say return at the bottom because it's supposed to be a script? I'm using GMS 1.4 btw.
// Remember these for later
var _x = argument0;
var _y = argument1;
var _obj = argument2;
var _mask = argument3;
var _xsc = argument4;
var _ysc = argumen5;
var _ang = argument6;
var xx = x, yy = y, msk = mask_index, xsc = image_xscale, ysc = image_yscale, ang = image_angle;
// Move to position and apply fields
x = _x; y = _y; image_xscale = _xsc; image_yscale = _ysc; image_angle = _ang;
// This is the bread and butter. Try not to stand up too fast!
var _r = place_meeting(x,y,_obj);
// Move everything back
x = xx; y = yy; mask_index = msk; image_xscale = xsc; image_yscale = ysc; image_angle = ang;
return _r;