V
viniciuscsg
Guest
Hello everyone,
The xyz collision code I am using in 2.5d seem to work well despite being still a cuboid collision (rectangular in all dimensions, disregards masks). I have adapted the reasoning from a number of true 3d collision examples, and it worked well in zeldaesque topdown with depth = -y and its variations, so characters can now jump, go under or over flying blocks and moving platforms, climb walls etc. Now, optimization issues:
At first I had the fps drop far below 60 (30-40ish) with as few as 5 or so instances of gravity and collision enabled "active" objects. After transposing all collision and gravity code out of the actual objects onto a single controller_obj (a trick I got from studying bullet hell games), I got it to hold 58-59ish fps with a maximum of 9-11 of those live instances on the room (which will do as baddies and whatnot). Still, I am not comfortable with that, slightly larger rooms would likely need to be populated with more of those active instances, and with more than 12 it goes down to 20-30 fps quite fast.
I need to now if this code is really so intensive as to cause that level of slowdown. The collision code rests on this cube_meeting function which is like collision rectangle in 3d, returning true or false:
Then the cube_meeting function is used to check for pixel perfect collisions in all 3 dimensions (considering the speed, and using the "while" method):
As I said, I managed to halve the fps hit by running all the code from a single controller obj, in its step event:
The number of passive instances (used as target to check collisions with) seems to be non issue since their objects carry no code at all, even when I am using from 100 to 200 of them as blocks to make up platforms and walls. I know I should probably learn to use tiles or surfaces to make up the level instead of so many object instances, but they carry the z and "z_height" information for multiple levels rooms, and I am planing for some of them to be destructible, have multiple z heights to work as ramps etc. I don't think tiles can do that.
Thank you very much in advance for any help or input you could give me on this.
The xyz collision code I am using in 2.5d seem to work well despite being still a cuboid collision (rectangular in all dimensions, disregards masks). I have adapted the reasoning from a number of true 3d collision examples, and it worked well in zeldaesque topdown with depth = -y and its variations, so characters can now jump, go under or over flying blocks and moving platforms, climb walls etc. Now, optimization issues:
At first I had the fps drop far below 60 (30-40ish) with as few as 5 or so instances of gravity and collision enabled "active" objects. After transposing all collision and gravity code out of the actual objects onto a single controller_obj (a trick I got from studying bullet hell games), I got it to hold 58-59ish fps with a maximum of 9-11 of those live instances on the room (which will do as baddies and whatnot). Still, I am not comfortable with that, slightly larger rooms would likely need to be populated with more of those active instances, and with more than 12 it goes down to 20-30 fps quite fast.
I need to now if this code is really so intensive as to cause that level of slowdown. The collision code rests on this cube_meeting function which is like collision rectangle in 3d, returning true or false:
Code:
///cube_meeting(x, y, z, obj)
xx = argument0; yy = argument1; zz = argument2; obj = argument3;
with (obj)
{
var ww = other.mask_width; var hh = other.mask_height; var zh = other.zheight;
if (other.xx > x - ww && other.xx < x + ww && //check horizontal overlap
other.yy > y - hh && other.yy < y + hh && //check vertical overlap
other.zz > z - zh && other.zz < z + zheight) && //check z overlap
(other.id != id) //check for "notme"
{
return true;
}
}
return false
Code:
///cube_collision(obj)
obj = argument0;
if (!cube_meeting (x + hspd, y, z, obj)) { x += hspd; } //can move
else { while (!cube_meeting(x + hspd, y, z, obj)) { x += sign(hspd); } hspd=0 }
if (!cube_meeting (x, y + vspd, z, obj)) { y += vspd; } //can move
else { while (!cube_meeting (x, y + vspd, z, obj)) { y += sign(vspd); } vspd =0 }
if (!cube_meeting (x, y, z + zspd, obj)) { z +=zspd } //can move
else { while (!cube_meeting(x, y, z + zspd , obj)) { z += sign(zspd); } zspd =0 }
Code:
/// Handles collisions of all active objects and update their depths (depth=-y+z)
with parent_active {
cube_collision(parent_all)
scr_get_depth() }
Thank you very much in advance for any help or input you could give me on this.