Jump to content


Photo

Precise 3D Collisions Dll (P3DC.dll) V6.1


  • Please log in to reply
375 replies to this topic

#21 Jepie0

Jepie0

    GMC Member

  • GMC Member
  • 213 posts

Posted 19 October 2009 - 12:56 AM

Iv'e run into a slight problem with your dll. Using the raycasting i get awesome fps doing 20 checks every step and i still get 100fps. The ray casting checks a 8192 poly terrain model. But i recently started doing model compare checks to allow a player character to move around the environment etc. But the fps took a huge hit when doing model compares. I made a simple seperate 3d game with just 30 crates that can move and collide with each other. The fps would drop down to 20-25fps. Would it be a issue with the dll or just a limitation that can't be overcome.

Below is the script i made to check for collisions before moving a crate.
// scr_d3d_model_collision();
// argument0: calling id
// argument1: calling collision id
// argument2: calling x pos
// argument3: calling y pos
// argument4: calling z pos
// argument5: object to check

if (argument5 != -1)
{
	with(argument5)
	{
		if (argument0 != id)
		{
		if (col_id != -1)
		{
			// static collision
			if (col_type = 0)
			{
				if (p3dc_check_still(argument1,argument2,argument3,argument4,col_id) = true)
				{
					argument0.obj_id = id;
					return true;
					exit;
				}
			}
			
			// dynamic collision
			if (col_type = 1)
			{
				if (p3dc_check(argument1,argument2,argument3,argument4,col_id
,x,y,z) = true)
				{
					argument0.obj_id = id;
					return true;
					exit;
				}
			}
		}
		}
	}
}

return false;

// crate step event
// movement
if (scr_d3d_model_collision(id,col_id,x+x_speed,y,z,obj_col_parent) = false)
{
	x += x_speed;
} else x_speed = 0;
		
if (scr_d3d_model_collision(id,col_id,x,y+y_speed,z,obj_col_parent) = false)
{
	y += y_speed;
} else y_speed = 0;

// friction
spd = point_distance(0,0,x_speed,y_speed);
spd_dir = point_direction(0,0,x_speed,y_speed);
	
if (spd > 0)
{
	if ((spd-0.1) > 0) spd -= 0.1; else spd = 0;
	x_speed = lengthdir_x(spd,spd_dir);
	y_speed = lengthdir_y(spd,spd_dir);
}

Thanks, Jepie0
  • 0

#22 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 20 October 2009 - 01:38 AM

I'm not sure if you're doing this or not; but do not collision check the terrain, this can be done with a few raycasts. (Which are much faster; as you've figured out). The problem checking for collisions is that it runs through a loop of every triangle and checks it against every other triangle in the model. So if you're checking one triangle against the 8192 poly one, that's 8192 checks. If you're checking two thats 8192*2, if three thats 8192*3 and so on...

***Add this, it'll increase speeds alot***
***For objects only; does not work for the level***
Only do a collision check if there is a collision on the X,Y axis. This can be done with a circle sprite (equal to the radius of the model) and the collision event (make sure its NOT solid, or you'll have GM reacting to collisions on the X,Y axis). Then in the collision event check for collisions with p3dc (Collision event will not be precise on the X,Y axis and does not take the Z into account, however using it in combination with p3dc can be powerful and will improve speeds)
***********************************

There are also other ways to overcome this (I'm sure there's more, but this is what I'd do).

A: Make the models lower poly (if possible), this will reduce the number of checks needed (a little change on the big models does not effect it as much as little changes on the smaller models; however it all helps)

B: Split your levels/models (collision model) into many smaller ones (X,Y axis only), and collision check against the only needed one. Then create one big models to use for raycasting (contains everything). So for example say you had a 64x64 terrain, split that into a 8x8 array of models, each containing pieces of the large one corresponding to the position on the large one.
Also make it larger (+1,-1) on the sides/top bottom so that the spots will slightly overlap.

model[0,0] contains the height spots [0-8,0-8] for the heights
model[1,0] contains the height spots [7-17,0-8] for the heights
model[2,0] contains the height spots [15-25,0,8] for the heights
model[6,3] contains the height spots [41-51,23-33] for the heights

This does not have to be done by hand, and should be done inside of a loop.

then when checking what model to compare to...
modelcheck=floor(x/SIZEOFTHESQUAES*8);
and collision check against that.

C: Use a couple raycasts and shoot them out of the that each face of the cube is pointing


BTW: I don't plan on adding the groups; I looked at them, and it would be faster to do with GML

Edited by brett14, 20 October 2009 - 01:40 AM.

  • 0

#23 Jepie0

Jepie0

    GMC Member

  • GMC Member
  • 213 posts

Posted 20 October 2009 - 10:44 AM

Thanks for the tips Brett the box example was just 12 polygon cratesx30 that could move, there was no terrain or floor involved. Using Gm's inbuilt x,y collisions will probably be a good work around. Thats ok about not having groups iv'e already made the scripts i need to work around it. Are u still going to add normal support? otherwise i will have to use Tepi or iccurds script on top of yours.

Thanks, Jepie0
  • 0

#24 DmitriV

DmitriV

    GMC Member

  • GMC Member
  • 11 posts

Posted 20 October 2009 - 09:03 PM

Could you also make an example with simple models. I don't understand it anymore with (map.map) and all the codes form the modmod collision checking. I just want a clear example, a bit to the point... :)

And a last question: what does p3dccolid do?? And how do I make a collision checking code with seperate models? Just add them to one big model like in the Starters example??

Thx, DmitriV
  • 0

#25 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 20 October 2009 - 11:08 PM

p3dc_colid();
checks if there is a collision between two models, both of which can move. So for example this can be used to check if objects have run into each other (example two players).
p3dc_colid_still();
also checks if there is a collision between two models, however in this case only one can move. So for example this can be used to check objects against the level.



I'll try to upload a new example asap.
  • 0

#26 DmitriV

DmitriV

    GMC Member

  • GMC Member
  • 11 posts

Posted 21 October 2009 - 03:50 PM

No, I mean: What does this:
if(p3dc_check_still(p3dc_collision,tox,toy,z-3,p3dccolid)==1){

Is p3dccolid the whole model?

Where is the whole model defined and added to the collision checking?
In the Starters example its done here:

with(block_0){
p3dc_add_block(x-16,y-16,0,x+16,y+16,32); // <------------ Here it's done -------
d3d_model_block(global.level_model,x-16,y-16,0,x+16,y+16,32,1,1);
instance_destroy();//The object is no longer needed, we destroy it
}

But I can't find that in the experts example...


In my game I've this:
global.fence = d3d_model_create();
global.house = d3d_model_create();
...

d3d_model_load(global.fence,'fence/fence.gmmod');
d3d_model_load(global.house,'objects/house.gmmod');
...

And then:
d3d_model_draw(global.fence,x,y,0,background_get_texture(tx_fence));

How do I add that to my collision checking

Edited by DmitriV, 21 October 2009 - 03:57 PM.

  • 0

#27 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 24 October 2009 - 05:55 AM

Okay sorry about the delayed reply;


Re-download the new version and look at example 2. It will show you how to do everything you'll need. In the create event it will show you how to add game maker .d3d models to your collision model.


Example 1 shows you how to set p3dc up, and use GM primitives.
Example 3 is just like the old experts example, however faster.

But I can't find that in the experts example

In the old example it was done through a bunch of complex scripts to load the model from a custom format... sorry about that; I should have made an in between example sooner.

[EDIT]
if(p3dc_check_still(p3dc_collision,tox,toy,z-3,p3dccolid)==1){
yeah, that has been cleared up (I have used better names in the new version). Anyways p3dc_collision is the player model (a block, all we need) and p3dccolid was the level model.
[/EDIT]

[EDIT2]

Are u still going to add normal support

Most likely not; I don't know how this would work (even with you're help and code)
~Sorry ^_^ ...
[/EDIT2]

Edited by brett14, 24 October 2009 - 07:21 AM.

  • 0

#28 Robert3DG+

Robert3DG+

    VR Games

  • GMC Member
  • 1851 posts
  • Version:GM:Studio

Posted 26 October 2009 - 12:21 AM

I really loved this man, smooth, fast and very efficient.

Suggestions:

Ellipsoid support (Very useful for making hills and such)
Rotations (So we can rotate basic shapes and such to give our levels greater variety)
A nice logo (So when I put you in the credits it's not just some boring text :))


Also would it be possible to make a demo showing like individual cube objects that the player can collide into? In the first demo you only have one object that creates every collision into one big collision model which is useful in some cases but what would we do if we just wanted individual player collisions based on a multitude of objects rather then just one big check? It would be lovely if you made an example showing how to do this. (It's a pain drawing a whole level using only one object :) )

Looking forward to your reply, keep up the excellent work!

-Rob
  • 0

#29 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 26 October 2009 - 01:13 AM

Ellipsoid support

As stated in the first post the only reason this is not included is I can't find an ellipsoid script that produces the exact same result as gamemakers does (I made one before, but i lost it when i reformatted my computer)

Rotations

Possibly coming soon; however I have other priorities at the moment.

A nice logo

Don't have photoshop, the only image minipulation program I have is MS paint... I'll try to get something though.



I'll make an example like that. I'll also make one for shooting multiple objects.



PS: Everything is handled in one object because it is faster
~~Brett14;
  • 0

#30 Robert3DG+

Robert3DG+

    VR Games

  • GMC Member
  • 1851 posts
  • Version:GM:Studio

Posted 26 October 2009 - 01:37 AM

I know it's for speed but for the speed, such an example would just be for quick level design and testing. After the level was built a script to save all the geometry data from each object into a .txt file could be made I imagine to put it all into one object.

Thanks for looking into the tutorial, can't wait see it :)
  • 0

#31 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 October 2009 - 02:17 AM

Just a suggestion: Paint.NET is amazing for the price (free).
For the ellipsoid, it may be nice to have a mathematically "perfect" check as well. That would be easier that generating a model, but would also obviously not match a very low-poly gm ellipsoid.

Edited by hanson, 26 October 2009 - 03:28 AM.

  • 0

#32 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 26 October 2009 - 02:59 AM

@hanson.
I'll look into Pain.NET (or did you mean paint.net?)


I've actually already added a perfect ellipsoid check (comparing distance between the two points to the radius of the model and ellipsoid); however it is not in this version. I added it about 2 hours after I uploaded it. Thanks for the suggestion though.

[EDIT]
I think you meant paint.net (that's what I'm getting right now). Thanks
[/EDIT]


~Brett14;

Edited by brett14, 26 October 2009 - 03:02 AM.

  • 0

#33 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 October 2009 - 03:47 AM

Yes, I meant paint.net - sorry 'bout that

keep up the good work!
-hanson
  • 0

#34 Robert3DG+

Robert3DG+

    VR Games

  • GMC Member
  • 1851 posts
  • Version:GM:Studio

Posted 27 October 2009 - 01:23 AM

I'm already a wicked ace with building levels out of cones and cylinders and stuff so if Brett gets that example made I should have a real good platforming game tech demo made in return :)

Seriously, this .DLL should be an essential in every 3D GameMaker game. It fully deserves that title. With ellipsoids on the way and possible rotations in the future it really only get's better from here!
  • 0

#35 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 27 October 2009 - 03:35 AM

Might be at the end of this week though (or even the start of next week), I'm swamped with school, sports, homework, and activities throughout the week. And my weekend is all taken up with Halloween, Paintball, Soccer etc. Not much free time lately, and I'm also working on a few projects so I'll try and get a new version and example up ASAP, however like said before it might be about a week (or a little longer).

Sorry 'bout that...
~~Brett14;

Edited by brett14, 27 October 2009 - 03:36 AM.

  • 0

#36 Robert3DG+

Robert3DG+

    VR Games

  • GMC Member
  • 1851 posts
  • Version:GM:Studio

Posted 28 October 2009 - 02:36 AM

That's quite alright, I'm in the middle of trying to figure out how to do it myself.

I get how you must set up the invisible collision model and then draw the actual visual representation of it, the only confusing part is making the player be able to collide with every geometry piece I throw in the world instead of doing one check on just one big collision model that was generated by one object (As it is in Example 1) as opposed to many like I need.

However I'm still experimenting and I'm liking what I'm seeing, and yeah, school can be annoying (Junior in High School this year =P)
  • 0

#37 oiioii

oiioii

    GMC Member

  • New Member
  • 50 posts

Posted 18 November 2009 - 11:23 PM

EXELENT improvement of the DLL
Thanks!!! The speed gets a waaay better!!! :)
Using in my game with HXS2007
  • 0

#38 RamboFox

RamboFox

    Tainted Fortune

  • New Member
  • 992 posts

Posted 22 November 2009 - 03:51 AM

This dll runs so much faster than ModMod - it's helping me heaps!

Just one thing; Is it possible to return a raycasted model's ID, and it's parent instance? (I would like to know whether, for example: My bullet hit the terrain, or an enemy character instead)
  • 0

#39 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 22 November 2009 - 10:00 PM

Yes, it is possible. Below is a [template] of how this would work. It may look like a lot, but most of it is comments, so it is actually quite simple. Use two variables, one to store the id of the hit object, and another to store the distance to it. These are the variables dis and hit.


dis=p3dc_ray_still(levelcolid,x,y,z,vx,vy,vz);//shoot to see how far it is to the level, Returns 0 if shot into space
hit=noone;//Currently we have shot nobody -> This will remain noone if nobody was shot.

//hit an enemy
with(obj_enemy){
var d;
d=p3dc_ray(global.bot_collision,x,y,z-5,other.x,other.y,other.z,other.vx,other.vy,other.
vz);//check to see if there was a collision with this player in the given direction
	if(d<other.dis){//if there was a collision AND it was less than the distance to the level
	other.dis=d;//The distance is now to this player (he's the closest)
	other.hit=id;//We set hit to this objects id, becuase we hit it.
	}
}
//hit an ally
with(obj_ally){
var d;
d=p3dc_ray(global.bot_collision,x,y,z-5,other.x,other.y,other.z,other.vx,other.vy,other.
vz);//check to see if there was a collision with this player in the given direction
	if(d<other.dis){//if there was a collision AND it was less than the distance to the level
	other.dis=d;//The distance is now to this player (he's the closest)
	other.hit=id;//We set hit to this objects id, becuase we hit it.
	}
}
//Repeat the above code for every object that you want to be able to be shot, or just make a parent and detect against it.

//************************************//
//****BELOW IS THE REACTION, ABOVE IS THE DETECTION****//
//************************************//


if dis==0 exit;//Nothing was hit, he shot into space

//We hit the level, do whatever
if(hit==noone){
//EFFECT
exit;//exit --> Needed, so it doesn't continue down to the code below
}

//We hit an object
with(hit){
//What to do with the hit object, for example kill it
instance_destroy();//<--Change this
}

Hope that helps you
~~Brett14;


[REASON FOR EDIT]
Adding more comments to the code, fixing it's format
[/EDIT]

Edited by brett14, 22 November 2009 - 10:05 PM.

  • 0

#40 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 25 January 2010 - 09:28 AM

This is a quick 3D collision dll. I'm very impressed! :medieval:
I do have a slight issue though.
I used this to make my first 3D First person shooter, and I used to get a solid 60/60 FPS.
But my project has moved to GM8, not GM7. And now I only get a maximum of 54/60 FPS.

Any ideas why?
Or maybe fixes to the dll?

-MoK
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users