Maarten Baert's website

Game Maker / C++ projects

Home Model Creator ExtremePhysics Game Maker DLLs   Recent comments Search

Last modified: Thu, 25 Feb 2010
Refresh

Tutorials



Comments

Tenkeral

Comment #1: Wed, 23 Jun 2010, 10:53 (GMT+1, DST)

Quote


he program asks me the file "Extreme Physics 2.1.dat" and the download does not contain this. Is there any solution?

Maarten Baert

Administrator

Comment #2: Wed, 23 Jun 2010, 16:23 (GMT+1, DST)

Quote


Quote: Tenkeral

he program asks me the file "Extreme Physics 2.1.dat" and the download does not contain this. Is there any solution?

You probably tried to install the extension by copying the GEX file to the extensions folder. This is not the correct way to install extensions in GM. You should delete the GEX again and install it correctly. You have to install the extension using the 'Install' button in GM (Resources > Select Extensions > Install > Install). GM will ask you to select the GEX file. Select the file and GM will install the extension for you. After installing you can delete the original file (but not the files GM has created in the extension folder).

Last modified: Wed, 23 Jun 2010, 16:25 (GMT+1, DST)

Retarded_lemon

Comment #3: Fri, 6 Aug 2010, 4:00 (GMT+1, DST)

Quote


PERFECT PERFECT PERFECT, this is a briliant physics engine, and however extensive your tutorials are, I am not sure on one thing. I have been playing around in the engine_example and have set up a simple drawing system where you draw a shape and well, it gets created. To do this i was using your new multipoly system but the fact that you must create polygons clock-wise and they must join up defeated the purpose I had in mind, so I decided to make the new object create several line-shapes in the one body, which works perfectly but... To see the body I have to use the usedebugdraw. So, is there a way I can find all the points in a body or is there another solution.

PS. I am extremely fluent in gml but only know very minimal c++

Many thanks

Retarded Lemon

Omaga

Comment #4: Sat, 7 Aug 2010, 21:28 (GMT+1, DST)

Quote


Is there a sample .gmk file that uses this? I would like to use the dll but I cant seem to put it to use in my game. A great example would be where a few objects in a topdown can be moved, and do there physics stuff like collisions.

And would it be possible to include this in a game that allready has controld movement with the v&hspeed that is allready part of GM? (I have a feeling I may have compatibility problems beacuse of this)

Last modified: Sat, 7 Aug 2010, 21:41 (GMT+1, DST)

Retarded_lemon

Comment #5: Mon, 9 Aug 2010, 1:35 (GMT+1, DST)

Quote


@ Omaga: Yes it would be possible to embed this physics engine into your game, and the hspeed/vspeed shouldn't cause too much of a problem. If you need just a basic examlple look at the engine example included with the engine, if you want top down physics just look for any lines of code in the create event like this:
ep_body_set_gravity(global.world,body,0,0.2);
and remove them. You would still need to slow the objects down or it will seem like it is on ice.

@ Maarten: Could you set up a PM System and allow members to start threads. That sort of system might be better than using your tutorial section for our needs... just an idea.

Maarten Baert

Administrator

Comment #6: Tue, 10 Aug 2010, 20:26 (GMT+1, DST)

Quote


Quote: Retarded_lemon

PERFECT PERFECT PERFECT, this is a briliant physics engine, and however extensive your tutorials are, I am not sure on one thing. I have been playing around in the engine_example and have set up a simple drawing system where you draw a shape and well, it gets created. To do this i was using your new multipoly system but the fact that you must create polygons clock-wise and they must join up defeated the purpose I had in mind, so I decided to make the new object create several line-shapes in the one body, which works perfectly but... To see the body I have to use the usedebugdraw. So, is there a way I can find all the points in a body or is there another solution.

PS. I am extremely fluent in gml but only know very minimal c++

Many thanks

Retarded Lemon

Since you created the line shapes I guess you can also remember where they are. All you need is a function to convert local coordinates to world coordinates, and there are a few functions that can do this: coordinate and vector conversions. Does this answer your question, or do you need something else?

Quote: Retarded_lemon

@ Maarten: Could you set up a PM System and allow members to start threads. That sort of system might be better than using your tutorial section for our needs... just an idea.

I'm programming this website myself so this will probably take some time, but I think it shouldn't be too hard since I've already created this comment system.

Ccj

Comment #7: Tue, 17 Aug 2010, 17:18 (GMT+1, DST)

Quote


Hello Maarten,

Amazing job with both the Model Creator and ExtremePhysics! Regarding the the latter: is it possible to 'rig' pre-existing sprites with an ExtremePhysics body armature to give said sprites 2D physics properties?

Maarten Baert

Administrator

Comment #8: Thu, 19 Aug 2010, 14:28 (GMT+1, DST)

Quote


Quote: Ccj

Hello Maarten,

Amazing job with both the Model Creator and ExtremePhysics! Regarding the the latter: is it possible to 'rig' pre-existing sprites with an ExtremePhysics body armature to give said sprites 2D physics properties?

Sure, you can use polygons to do that. GamerXP has made a program that generates code for polygons. You can download it here:
http://sprites.3dn.ru/Uploads/Files/PolygonCreator.rar

Ccj

Comment #9: Thu, 26 Aug 2010, 8:26 (GMT+1, DST)

Quote


I downloaded GamerXP's program (awesome tool!) and experimented with adding polygons to sprites, but I'm still having trouble achieving the desired effect. What I'd really like to emulate is a 'soft body' effect, such that if I drop the object within whose creation event I placed the txt output from GamerXP's program [replacing sprite_index with the name of the sprite] the region of the sprite I defined with the polygon will bounce distinctly from the rest of the sprite, as if it were fatty or disconnected tissue etc. How would I go about setting up a spring/damping effect on the polygon region in order to make this work?

Thanks,

CCJ

Eddys12

Comment #10: Fri, 27 Aug 2010, 15:12 (GMT+1, DST)

Quote


um i need help with your model creator how do you add textures to individual parts of the model instead of the whole model and why cant textures be put in triangles?

Ash123987

Comment #11: Mon, 30 Aug 2010, 21:19 (GMT+1, DST)

Quote


I need help opening the file its a dll file and it says i cant open so i went to a suggest download to help open and it still doesnt work. Ive tryed 2 diffrent programs i tried changing the file name if thats what you were trying to tell me in the tutorial non of it works...

Maarten Baert

Administrator

Comment #12: Wed, 1 Sep 2010, 18:11 (GMT+1, DST)

Quote


Quote: Ccj

I downloaded GamerXP's program (awesome tool!) and experimented with adding polygons to sprites, but I'm still having trouble achieving the desired effect. What I'd really like to emulate is a 'soft body' effect, such that if I drop the object within whose creation event I placed the txt output from GamerXP's program [replacing sprite_index with the name of the sprite] the region of the sprite I defined with the polygon will bounce distinctly from the rest of the sprite, as if it were fatty or disconnected tissue etc. How would I go about setting up a spring/damping effect on the polygon region in order to make this work?

Thanks,

CCJ

Things like that are very difficult to make. There's a simple soft body example in the testbed, but I don't think it's suitable for what you're trying to do. You could try using small spheres connected to springs, but I'm not sure whether this will give the effect you want.

Quote: Ash123987

I need help opening the file its a dll file and it says i cant open so i went to a suggest download to help open and it still doesnt work. Ive tryed 2 diffrent programs i tried changing the file name if thats what you were trying to tell me in the tutorial non of it works...

What are you trying to do? You don't have to open the DLL, just put it in the game directory and use the scripts ...

Quote: Eddys12

um i need help with your model creator how do you add textures to individual parts of the model instead of the whole model and why cant textures be put in triangles?

You can only use one texture per model because GM supports only one texture per model. If you need multiple textures you should either combine the textures in one image, or use multiple models.

Last modified: Wed, 1 Sep 2010, 18:18 (GMT+1, DST)

Ccj

Comment #13: Thu, 9 Sep 2010, 16:21 (GMT+1, DST)

Quote


Hmm, OK I'll check out the example you mentioned and give the spheres on springs technique a try. Would the latter actually be able to deform the sprite it was bound to though?

So far the only technique for applying physics-related animation to raster sprites that I've seen work is to cut the sprites into component parts at their 'joints' and then build an armature linking these components (this was done with IK bones in Flash and Anime Studio 7 Pro). It looks all right, but if it's not done just right the animations end up looking unnaturally stiff. I'd really like to see a technique that could rig raster sprites for predictable movement/deformation like that which can be achieved with vector sprites or 3d meshes; hopefully GamerXP's polygon program and extremephysics can help with that!

Thanks,

CCJ

Ccj

Comment #14: Fri, 10 Sep 2010, 23:23 (GMT+1, DST)

Quote


Ah yes, one more question-- if I have a 2.5D mesh (by which I mean a flat mesh of polygons making up my model shape to create the 'fake 3d' effect) created in an external program, how would I set it up as an extreme physics body? What about for a true 3d mesh? How would I find out the various vertex coordinates of these meshes within the extreme physics world (and would I even need to)?

Thanks,

CCJ

Maarten Baert

Administrator

Comment #15: Sun, 12 Sep 2010, 18:09 (GMT+1, DST)

Quote


Quote: Ccj

So far the only technique for applying physics-related animation to raster sprites that I've seen work is to cut the sprites into component parts at their 'joints' and then build an armature linking these components (this was done with IK bones in Flash and Anime Studio 7 Pro). It looks all right, but if it's not done just right the animations end up looking unnaturally stiff. I'd really like to see a technique that could rig raster sprites for predictable movement/deformation like that which can be achieved with vector sprites or 3d meshes; hopefully GamerXP's polygon program and extremephysics can help with that!

It's possible with textured primitives :).

Quote: Ccj

Ah yes, one more question-- if I have a 2.5D mesh (by which I mean a flat mesh of polygons making up my model shape to create the 'fake 3d' effect) created in an external program, how would I set it up as an extreme physics body? What about for a true 3d mesh? How would I find out the various vertex coordinates of these meshes within the extreme physics world (and would I even need to)?

Do you mean a model in GM? In that case you can't, GM doesn't have any functions to get the coordinates of vertices in a model. But if you're using a loading script you might be able to extract the coordinates.

By the way, I've added a new example about soft bodies to the testbed.

Last modified: Sun, 12 Sep 2010, 18:09 (GMT+1, DST)

Ccj

Comment #16: Thu, 16 Sep 2010, 21:21 (GMT+1, DST)

Quote


Textured primitives are basically what I'm talking about when I mention 2.5D meshes. I have a flat polygon mesh tracing of a sprite [that I did in Blender] which I then textured with the sprite's original image. Is there a way I could apply extremephysics properties to it? (Note also that I am using the Ultimate 3D 2.1 extension, which I'm fairly sure gives me the functions I need to retrieve vertex information)

Alternatively, can polygons/multipolygons created using GamerXP's program be textured like flat primitives? If I could do that the process of applying extremephysics properties to the resultant mesh would be easy since its vertex information would already be available and formatted specifically for extremephysics. Also, is there a way to convert polygons/multipolygons created for use with extremephysics into standard format meshes which could be imported into an external 3d modeling program or loaded as models within GM using ultimate 3d?

Thanks,

CCJ

Maarten Baert

Administrator

Comment #17: Fri, 17 Sep 2010, 21:45 (GMT+1, DST)

Quote


Quote: Ccj

Textured primitives are basically what I'm talking about when I mention 2.5D meshes. I have a flat polygon mesh tracing of a sprite [that I did in Blender] which I then textured with the sprite's original image. Is there a way I could apply extremephysics properties to it? (Note also that I am using the Ultimate 3D 2.1 extension, which I'm fairly sure gives me the functions I need to retrieve vertex information)

Alternatively, can polygons/multipolygons created using GamerXP's program be textured like flat primitives? If I could do that the process of applying extremephysics properties to the resultant mesh would be easy since its vertex information would already be available and formatted specifically for extremephysics. Also, is there a way to convert polygons/multipolygons created for use with extremephysics into standard format meshes which could be imported into an external 3d modeling program or loaded as models within GM using ultimate 3d?

Thanks,

CCJ

If you can get the vertex data from U3D (in clockwise order), it should be possible. If you have the coordinates of the vertices you can just create a polygon (or multipolygon if the mesh is not always convex), and use that polygon/those polygons for the body. If you don't know how to use multipolygons, read this.

If you can't get the vertex data from U3D, you can also create the polygons with GamerXP's program (or any other program), use the multipolygon functions to subdivide it, use the functions to get the coordinates of vertices to copy the vertex data to an array in GM, and draw that using primitives. That's how I made the walls in my game The Machine. This is the code I used:

// subdivide the polygon
ep_world_multipoly_begin(global.world, vertices);
for(i = 0; i<vertices; i += 1) {
    ep_world_multipoly_set_vertex(global.world, i, vertex_x[i], vertex_y[i]);
}
if !ep_world_multipoly_end(global.world, false) {
    exit;
}
first_poly = ep_world_multipoly_get_first(global.world);
last_poly = ep_world_multipoly_get_last(global.world);
polys = last_poly-first_poly+1;

// create 3d model (for performance)
w = background_get_width(bg_tex_solid);
h = background_get_height(bg_tex_solid);
model = d3d_model_create();
for(i = 0; i<polys; i += 1) {
    c = ep_polygon_get_vertex_count(global.world, first_poly+i);
    d3d_model_primitive_begin(model, pr_trianglefan);
    for(j = 0; j<c; j += 1) {
        xx = ep_polygon_get_vertex_x(global.world, first_poly+i, j);
        yy = ep_polygon_get_vertex_y(global.world, first_poly+i, j);
        d3d_model_vertex_texture(model, xx-0.5, yy-0.5, 0, xx/w, yy/h);
    }
    d3d_model_primitive_end(model);
}
for(i = first_poly; i<=last_poly; i += 1) {
    ep_polygon_destroy(global.world, i);
}

EDIT: My BBCode parser isn't working correctly (it thinks the [i] in my code is a tag), I will try to fix it :P.

EDIT 2: Fixed.

Last modified: Fri, 17 Sep 2010, 21:54 (GMT+1, DST)

Chance

Comment #18: Mon, 4 Oct 2010, 4:39 (GMT+1, DST)

Quote


Hope this comment is in the right place...

Maarten, your engine is fantastic. I've only just started to use it, but I can see the potential. The functions are easy to understand and VERY powerful!

What an incredible contribution to the GM community you've made here. Thank you so much.

Retarded_lemon

Comment #19: Tue, 30 Nov 2010, 21:35 (GMT+1, DST)

Quote


If a player was standing on a block that was moving round in circles, and you wanted the player to stay on that block (as though the top of it was covered in super glue), what would be the best way to go about it?

Thanks

Retarded Lemon

Maarten Baert

Administrator

Comment #20: Fri, 10 Dec 2010, 20:30 (GMT+1, DST)

Quote


Quote: Retarded_lemon

If a player was standing on a block that was moving round in circles, and you wanted the player to stay on that block (as though the top of it was covered in super glue), what would be the best way to go about it?

Don't use ep_body_set_position to move the block, use ep_body_set_velocity_center instead. If you change the position of the body, ExtremePhysics doesn't know the block actually moved, so it can't simulate the movement correctly.

Retarded_lemon

Comment #21: Sat, 11 Dec 2010, 1:38 (GMT+1, DST)

Quote


Quote: Maarten Baert
Quote: Retarded_lemon

If a player was standing on a block that was moving round in circles, and you wanted the player to stay on that block (as though the top of it was covered in super glue), what would be the best way to go about it?

Don't use ep_body_set_position to move the block, use ep_body_set_velocity_center instead. If you change the position of the body, ExtremePhysics doesn't know the block actually moved, so it can't simulate the movement correctly.

I was using ep_body_set_velocity_center(), however there is not enough friction to hold the player at the correct position, I would increase friction but that then leads to the player being able to "stick" to walls. To combat that I would put in a check that only allows the player to move left/right if there is no collision, however that will prevent the player from pushing non static blocks. If I only check for static blocks then the player can still stick to a large pile of dynamic blocks. If I could remove virticle friction that would solve my problem as all dynamic blocks are set to "norotate", however I am unsure if I am able to do that.

Look forward to your response

Retarded Lemon

Maarten Baert

Administrator

Comment #22: Tue, 14 Dec 2010, 18:49 (GMT+1, DST)

Quote


Quote: Retarded_lemon

I was using ep_body_set_velocity_center(), however there is not enough friction to hold the player at the correct position, I would increase friction but that then leads to the player being able to "stick" to walls. To combat that I would put in a check that only allows the player to move left/right if there is no collision, however that will prevent the player from pushing non static blocks. If I only check for static blocks then the player can still stick to a large pile of dynamic blocks. If I could remove virticle friction that would solve my problem as all dynamic blocks are set to "norotate", however I am unsure if I am able to do that.

Look forward to your response

Retarded Lemon

I don't think friction is the problem here, the player is probably sliding off the block because the velocity is changed in the step event. You could disable this when the player isn't touching the ground (which would be more realistic) but this would make it impossible to control the player during a jump.

You could also try to use the collision functions to check whether the player is standing on a moving block, and adjust the controls accordingly. That might work ...

Johnmenez

Comment #23: Fri, 21 Jan 2011, 0:37 (GMT+1, DST)

Quote


This is what i'm looking for. Nice work. However, I have a question, how do I detect collision in ray casting?

Maarten Baert

Administrator

Comment #24: Tue, 25 Jan 2011, 18:11 (GMT+1, DST)

Quote


Quote: Johnmenez

This is what i'm looking for. Nice work. However, I have a question, how do I detect collision in ray casting?

ep_world_ray_cast returns -1 if there is no collision. If the return value is any other number, there is a collision.

Ross93

Comment #25: Wed, 2 Mar 2011, 3:05 (GMT+1, DST)

Quote


Hey there

I'm pretty new to using physics in games and I have a small question...

what's the difference between using forces and directly setting the velocity of an object?

if I have a character whose movement is controlled with the arrow keys, should I use forces?

Currently I am using ep_body_set_velocity_center in this way:

xx=ep_body_get_xvel_center(global.world, body)
yy=ep_body_get_yvel_center(global.world, body)
if keyboard_check(vk_up) then yy=-1 *movement_speed
else 
if keyboard_check(vk_down) then yy=1 *movement_speed
if keyboard_check(vk_left) then
{
    xx=-1 *movement_speed
    if keyboard_check(vk_up) then
    {
        xx=1 / sqrt(2) *-1 *movement_speed
        yy=1 / sqrt(2) *-1 *movement_speed
    }
    if keyboard_check(vk_down) then
    {
        xx= 1 /sqrt(2) *-1 *movement_speed
        yy= 1 /sqrt(2) *movement_speed
    }
}
else
if keyboard_check(vk_right) then
{
    xx=1 *movement_speed
    if keyboard_check(vk_up) then
    {
        xx= 1/sqrt(2) *movement_speed
        yy= 1/ sqrt(2) *-1 *movement_speed
    }
    if keyboard_check(vk_down) then
    {
        xx= 1/ sqrt(2) *movement_speed
        yy= 1/sqrt(2) *movement_speed
    }
}
ep_body_set_velocity_center(global.world, body, xx,yy,0)

where movement_speed is a constant defining how fast I want the character to move in the game

Cheers

Ross

Maarten Baert

Administrator

Comment #26: Sat, 5 Mar 2011, 19:08 (GMT+1, DST)

Quote


Quote: Ross93

Hey there

I'm pretty new to using physics in games and I have a small question...

what's the difference between using forces and directly setting the velocity of an object?

if I have a character whose movement is controlled with the arrow keys, should I use forces?

Currently I am using ep_body_set_velocity_center in this way:
[...]

where movement_speed is a constant defining how fast I want the character to move in the game

Cheers

Ross

ep_body_set_velocity_center is the equivalent of motion_set. ep_body_apply_impulse is the equivalent of motion_add. Forces are equivalent to calling ep_body_apply_impulse every step.

In many situations ep_body_apply_impulse or forces are more convenient than changing the velocity manually, but if you need more precise control it might be easier to use ep_body_get_xvel_center, ep_body_get_yvel_center and ep_body_set_velocity_center.

In any case, don't use ep_body_set_position to make the character move. This won't work properly because ExtremePhysics needs the velocity to simulate collisions and joints.

Last modified: Sat, 5 Mar 2011, 19:09 (GMT+1, DST)

Dillerkind

Comment #27: Thu, 10 Mar 2011, 13:30 (GMT+1, DST)

Quote


Hey Maarten..

I've been fiddling with EP for a little while now. You've done some great work with the engine. Stable, good performance and not too difficult to work with. Thumbs up and a big thank you for this!

However, I'd like to ask whether it would be possible to go a bit more into detail about some of the parameters in the documentation/tutorials. You know, like giving examples of practicable values for different parameters. Most of these require a lot of experimenting until you find proper values (some need to be rather smallish while others require quite big numbers in order to show any effect). I know, many depend on the size/weight of the bodies and such.. but some general examples might help here.

And the second thing is kind of a bug or something. It occured in your big-world example. When you drive that car into a corner, the wheel gets stuck there. This happened in my own project (little side-scrolling vehicle thingie.. not a game yet, just a little test to see what can be done with the engine :) ) as well. Two contacts with static bodies and you get stuck. I don't know whether somebody else has reported this yet, but I thought I'd let you know anyway.

Maarten Baert

Administrator

Comment #28: Tue, 15 Mar 2011, 20:35 (GMT+1, DST)

Quote


Quote: Dillerkind

Hey Maarten..

I've been fiddling with EP for a little while now. You've done some great work with the engine. Stable, good performance and not too difficult to work with. Thumbs up and a big thank you for this!

However, I'd like to ask whether it would be possible to go a bit more into detail about some of the parameters in the documentation/tutorials. You know, like giving examples of practicable values for different parameters. Most of these require a lot of experimenting until you find proper values (some need to be rather smallish while others require quite big numbers in order to show any effect). I know, many depend on the size/weight of the bodies and such.. but some general examples might help here.

The testbed contains a lot of example values, but it's not easy to find them. What functions did you have in mind?

Quote: Dillerkind

And the second thing is kind of a bug or something. It occured in your big-world example. When you drive that car into a corner, the wheel gets stuck there. This happened in my own project (little side-scrolling vehicle thingie.. not a game yet, just a little test to see what can be done with the engine :) ) as well. Two contacts with static bodies and you get stuck. I don't know whether somebody else has reported this yet, but I thought I'd let you know anyway.

That's because the friction of the wheels was set to 20 instead of 1 (20 isn't even physically possible). I will upload a new version.

Johnmenez

Comment #29: Mon, 28 Mar 2011, 10:12 (GMT+1, DST)

Quote


In your game, "the machine", the metal rods with many holes,(i don't know what it is) how do you drag the rods and rotate towards the mouse?

Maarten Baert

Administrator

Comment #30: Wed, 30 Mar 2011, 14:41 (GMT+1, DST)

Quote


Quote: Johnmenez

In your game, "the machine", the metal rods with many holes,(i don't know what it is) how do you drag the rods and rotate towards the mouse?

I used hinge joints to do that. There's an example that shows how it's done: picking_up_boxes.gmk (part of the ExtremePhysics ZIP file).

Vortex

Comment #31: Wed, 11 May 2011, 16:06 (GMT+1, DST)

Quote


I officially love you...
This is awesome!

Gboy

Comment #32: Tue, 24 May 2011, 15:38 (GMT+1, DST)

Quote


Hi Maarten!
First of all, congratulations for the awesome job you have done. I find EP relatively simple to use and I certainly would not define myself as a coder!
So, once again, thank you so much for the incredible engine you created!

I seem however not able to handle collisions properly when it comes to integrating your functions with GM's ones.
In particular, what I am trying to do, with any success so far, is the following:
I have a bullet object. It has a sprite, a body and a shape and it is dynamic. It moves using ep_body_apply_impulse_relative it receives when it is created, and it travels a straight line until he finds something. So far, everything works.
The problem is that I want the bullet to be destroyed once it collides either with enemies (dynamic bodies) and some environment objects (mostly static bodies) but I would like this event to be handled by EP and not by the Game Maker On Collision event for two reasons: first, the EP body and the bullet sprite do not coincide precisely so sometimes the body touches the other body before the sprite, resulting in a "bounce".
Second, for I want the bullet to knock enemies back according to the physics of the given world, so if I make the body smaller than the sprite and I use the On Collision event, the istance gets destroyed (setting an alarm up "desynchronizes" the physics) before the bounce(the sprite touches the other sprite before the body) and the result is no physics collision.

I think what I have not clear in my mind is how the contact and contact indexes work.
Is a contact created by two colliding bodies? From your tutorials it seems so (a contact is when the distance between two outer bodies < treshold), but then how do I store the bodies who made that contact? Does the contact index mean that index 0 = 1st contact, 1 = 2nd contact and so on?

What I have been trying so far is to use ep_world_collision_test_circle(global.world,8,x,y,0.1,1,2,3) to get the number of collisions the circle mask built on the body's shape does and then
if (coll_numb > 0) {
a= ep_world_get_collision_body(global.world,0);
other functions here
}

to get the id of the body the bullet collides with so to check if its an enemy or a tree and to destroy the istance according to the case.
This results in the bullet not appearing, probabily because the bullet's body touches the gun's body when it is created (although masks and groups are set properly - I think, since the bullet do not bounce or influences the body of the gun and viceversa-), while if I use 1 as the second argument in ep_World_get_collision I get an EP error saying that the body is not colliding while the bullet is traveling towards a body.

Also, I have not been able to find a way to relate the EP body id with the GM instance ID of the body. In other words, even if I get the ID of the body, how can I tell to EP that the body I got the ID from is the body (or a mask) of an instance of a GM "obj_block_static" object? Maybe this is more of an issue with my poor coding skills but understing how GM IDs and EP IDs relate between themselves would help a lot!

Sorry for the wall of text, and thanks in advance for your help!

And thanks again for creating EP!

Thootje

Comment #33: Sat, 28 May 2011, 14:32 (GMT+1, DST)

Quote


wow!
extreme physics is really great!

thootje

Maarten Baert

Administrator

Comment #34: Sun, 29 May 2011, 18:20 (GMT+1, DST)

Quote


Quote: Gboy

Hi Maarten!
First of all, congratulations for the awesome job you have done. I find EP relatively simple to use and I certainly would not define myself as a coder!
So, once again, thank you so much for the incredible engine you created!

I seem however not able to handle collisions properly when it comes to integrating your functions with GM's ones.

I've added a new tutorial, this should help:
Collision detection

Quote: Gboy

I think what I have not clear in my mind is how the contact and contact indexes work.
Is a contact created by two colliding bodies? From your tutorials it seems so (a contact is when the distance between two outer bodies < treshold), but then how do I store the bodies who made that contact? Does the contact index mean that index 0 = 1st contact, 1 = 2nd contact and so on?

If two bodies overlap, EP creates a contact. But a contact can have either one contact point (a point-edge collision) or two contact points (an edge-edge collision). But you don't need the contact points if you're just trying to detect collisions.

Contacts have ids just like bodies and shapes, the world has a counter to keep track of the ids. The first contact will get id 1, the next contact id 2, et cetera. But if contact 1 is destroyed, the counter stays the same, so the next contact will get id 3 even though there are only 2 contacts.

Quote: Gboy

Also, I have not been able to find a way to relate the EP body id with the GM instance ID of the body. In other words, even if I get the ID of the body, how can I tell to EP that the body I got the ID from is the body (or a mask) of an instance of a GM "obj_block_static" object? Maybe this is more of an issue with my poor coding skills but understing how GM IDs and EP IDs relate between themselves would help a lot!

The easiest way to do this is to store the id in a user variable. The tutorial shows how this works.

Last modified: Sun, 29 May 2011, 18:20 (GMT+1, DST)

Gboy

Comment #35: Mon, 30 May 2011, 11:57 (GMT+1, DST)

Quote


Quote: Maarten Baert

The easiest way to do this is to store the id in a user variable. The tutorial shows how this works.

Your new tutorial is God sent! Exactly what I needed to optimize my code!Many many thanks!
I would hug you right now if you were not out of reach :D

Beforehand I solved my collision problem with two workarounds in the bullet's step event.

This one was telling the bullet to destroy itself when a "virtual" collision with any kind of object (enemies and environment blocks) happens (the instance_destroy function was handled by the EP body updating script):

coll_numb = ep_world_collision_test_circle(global.world,8,x,y,0.1,2,1,1);

if (coll_numb = 1) {
    a= ep_world_get_collision_body(global.world,0);
        if (ep_body_exists(global.world, a)) {
        xcoll = ep_body_get_x_center(global.world, a);
        ycoll = ep_body_get_y_center(global.world, a);
        ep_body_apply_impulse_relative(global.world,a,xcoll,ycoll,xvel,yvel,0,1,1);
    }
    ep_body_destroy(global.world,bullet);
    coll_numb = 0;
}

while the following was controlling the damage done by the bullet (still in the stp event) in case it would have hit an object_enemy (the two virtual shapes in the two codes have different collision masks):

//Damages enemies

en_hit = ep_world_collision_test_circle(global.world,8,x,y,0.1,4,4,1);
 
if (en_hit = 1) {   
    b = ep_world_get_collision_body(global.world,0);
    x_body = ep_body_get_x_center(global.world, b);
    y_body = ep_body_get_y_center(global.world, b);
    with(obj_enemy) {
        if point_distance(x,y,other.x_body,other.y_body) <= 1 {
        en_health -= obj_damage_controller.shot_damage;
        }
    }
}

The system worked but it forced me to mess around too much with zillion of collision masks and it creates too many virtual shapes per object, messing up also the natural EP collisions handling. Not to mention the nested "if" statements and the distance checks between the body and the object - the "body update" script is made in such a way that the object's (x,y) follow the body's coordinates -. Your code avoids all the extra work both for me and for my poor processor and that's just great :D

Not only that, but I guess my poor code, by acting on virtual shapes, was somehow imparing EP native collision handling since bounces and impulses were "artificial". With your new tutorial all this is avoided, and that's just great!

Thanks again for the amazing work and for your kindness and availability!

Best wishes!

Tomcat2900

Comment #36: Mon, 25 Jul 2011, 22:19 (GMT+1, DST)

Quote


Hello !
I want to use the Extreme Physics for a ball game.
I tried 2 days to obtain what I want but I couldn't.
Please tell me how can I get the following result from the link below:

http://www.2shared.com/photo/X4QU8b3E/Balls.html

As you can see there the balls are aligned...

Please give me a sample.

Thank You!

Maarten Baert

Administrator

Comment #37: Tue, 2 Aug 2011, 2:48 (GMT+1, DST)

Quote


Quote: Tomcat2900

Hello !
I want to use the Extreme Physics for a ball game.
I tried 2 days to obtain what I want but I couldn't.
Please tell me how can I get the following result from the link below:

http://www.2shared.com/photo/X4QU8b3E/Balls.html

As you can see there the balls are aligned...

Please give me a sample.

Thank You!

That game is grid-based, ExtremePhysics isn't suitable for that kind of games. You should use a grid-based system. Did you read the official tutorial on maze games (link)?

Jomish

Comment #38: Fri, 26 Aug 2011, 18:49 (GMT+1, DST)

Quote


Maarten-I've been learning to work with your engine...By the way, thank you very much and very great job!

Problem:
I am an amateur GM programmer but have used other languages, and I can't seem to figure out this one out! Please help!!!

Details:
I loaded your platform example and from the code in it,
I was able to create dynamic/static objects (polys and multipolys) and attach sprites to them.

I place an object on a map where-in the create event executes code to create an obj_1 and I load a sprite to the obj_1 and it works fine (like in platform example)....

but when I try to join it with any joints I have to declare a second body, so I try to

ep_hingejoint_create(global.world,body1,body2,0,-20,0,0);

where body1 is declared first in the same event but body2 was declared in create event of other object in room (that way both objects would be created through different objects with different sprites, and interact in a cool way.

but body2 is declared unknown.

So now I made two bodies in the create event of obj_1 but the draw_sprite_corrected isn't showing up.

My question is how do I join to two different objects, obj_1 and obj_2?

p.s. (i hope i'm not too confusing...)
I also can't get the debug draw mode to draw anything!

Jomish

Comment #39: Fri, 26 Aug 2011, 19:30 (GMT+1, DST)

Quote


Maarten, here is my create object event code, but only one sprite (body) is draw and it flops off the screen

body = ep_body_create_dynamic(global.world,false);
//declaring body instance creation

global.multi_poly_arrow1 = ep_world_multipoly_begin(global.world,9);
// 9: number of vertices.

ep_world_multipoly_set_vertex(global.world,0,-39,-9);
ep_world_multipoly_set_vertex(global.world,1,0,-9);
ep_world_multipoly_set_vertex(global.world,2,0,-16);
ep_world_multipoly_set_vertex(global.world,3,4,-16);
ep_world_multipoly_set_vertex(global.world,4,25,0);
ep_world_multipoly_set_vertex(global.world,5,4,16);
ep_world_multipoly_set_vertex(global.world,6,-1,16);
ep_world_multipoly_set_vertex(global.world,7,-1,8);
ep_world_multipoly_set_vertex(global.world,8,-39,8);
ep_world_multipoly_end(global.world,true);

poly_first_0 = ep_world_multipoly_get_first(global.world);
poly_last_0 = ep_world_multipoly_get_last(global.world);

//ep_polygon_initialize(global.world,global.multi_poly_arrow1);
//intializing the polygon for use

shape1 = ep_shape_create_polygon(global.world,body,global.multi_poly_arrow1,0,0,0,1);

for(i=poly_first_0;i<=poly_last_0;i+=1) {
shape1 = ep_shape_create_polygon(global.world,body,i,0,0,0,0.1);
ep_shape_set_collision(global.world,body,shape1,1,1,0);
ep_shape_set_material(global.world,body,shape1,0.2,0.5,0,0);
}

ep_body_calculate_mass(global.world,body);
//mass & momentum calculations
ep_body_set_gravity(global.world,body,0,platformgravity);
//setting gravity on the object

//////////////

body2 = ep_body_create_dynamic(global.world, false);
//declaring body instance creation

global.multi_poly_arrow2 = ep_world_multipoly_begin(global.world,9);
// 9: number of vertices.

ep_world_multipoly_set_vertex(global.world,0,-39,-9);
ep_world_multipoly_set_vertex(global.world,1,0,-9);
ep_world_multipoly_set_vertex(global.world,2,0,-16);
ep_world_multipoly_set_vertex(global.world,3,4,-16);
ep_world_multipoly_set_vertex(global.world,4,25,0);
ep_world_multipoly_set_vertex(global.world,5,4,16);
ep_world_multipoly_set_vertex(global.world,6,-1,16);
ep_world_multipoly_set_vertex(global.world,7,-1,8);
ep_world_multipoly_set_vertex(global.world,8,-39,8);
ep_world_multipoly_end(global.world,true);

poly_first_0 = ep_world_multipoly_get_first(global.world);
poly_last_0 = ep_world_multipoly_get_last(global.world);

//ep_polygon_initialize(global.world,global.multi_poly_arrow2);
//intializing the polygon for use

shape1 = ep_shape_create_polygon(global.world,body2,global.multi_poly_arrow2,0,0,0,1);

for(i=poly_first_0;i<=poly_last_0;i+=1) {
shape1 = ep_shape_create_polygon(global.world,body2,i,0,0,0,0.1);
ep_shape_set_collision(global.world,body2,shape1,1,1,0);
ep_shape_set_material(global.world,body2,shape1,0.2,0.5,0,0);
}

ep_body_calculate_mass(global.world,body2);
//mass & momentum calculations
ep_body_set_gravity(global.world,body2,0,platformgravity);
//setting gravity on the object

ep_hingejoint_create(global.world,body,body2,39,16,39,16,0);

physics_object_set(body);
physics_object_set(body2);

Jomish

Comment #40: Sun, 28 Aug 2011, 2:13 (GMT+1, DST)

Quote


I was wondering in your "platform example" how you could create a hinge at the point of collision with the player and another object.

Dll1024

Comment #41: Fri, 9 Sep 2011, 3:07 (GMT+1, DST)

Quote


Hi
im begginer to extremePhysics. i wrote this code in key press event(spacebar) of a dynamic object:

ep_body_set_position(global.world, body, x, y-25, image_angle);

But after a few times pressing space button, game window fills with my object color!

Maarten Baert

Administrator

Comment #42: Sun, 11 Sep 2011, 1:27 (GMT+1, DST)

Quote


Quote: Jomish

but when I try to join it with any joints I have to declare a second body, so I try to

ep_hingejoint_create(global.world,body1,body2,0,-20,0,0);

where body1 is declared first in the same event but body2 was declared in create event of other object in room (that way both objects would be created through different objects with different sprites, and interact in a cool way.

but body2 is declared unknown.

That's because it's a local variable. You should really read a tutorial (or just the manual) about global vs. local vs. temporary variables in GM first, otherwise you will run into this kind of problems all the time :).

Quote: Jomish

I also can't get the debug draw mode to draw anything!

Read this if you're using GM8.1.

Quote: Jomish

I was wondering in your "platform example" how you could create a hinge at the point of collision with the player and another object.

It's definitely possible. Read the tutorial on collision detection first:
http://www.maartenbaert.be/extremephysics/tutorials/collision-detection/
You can use the coordinate conversion functions to calculate the correct local coordinates. But it's not easy, and if you're new to GM you should really learn the basics first.

Quote: Dll1024

Hi
im begginer to extremePhysics. i wrote this code in key press event(spacebar) of a dynamic object:

ep_body_set_position(global.world, body, x, y-25, image_angle);

But after a few times pressing space button, game window fills with my object color!

image_angle is in degrees, but ep_body_set_position expects radians (just like all other ExtremePhysics functions). You should use degtorad to convert it. Does this solve your problem?

Last modified: Sun, 11 Sep 2011, 1:36 (GMT+1, DST)

Solarboy

Comment #43: Thu, 29 Sep 2011, 6:57 (GMT+1, DST)

Quote


Hey Maarten, your physics engine rocks! Thank you so much for making it! I've made more progress in the months that I've been using it then the whole four years I've been working on my game.

Now for a question...

I'm trying to make an object, (A), bounce off another, (B), similarly to how light reflects off a mirror. So I need to calculate the normal of object (B) when (A) collides with it, thankfully you've got that covered with 'ep_contact_get_normal_x' and 'ep_contact_get_normal_y'.

So I made this code to return the normal in degrees:

contact=ep_shape_get_first_contact(global.world,body,shape)
normal_x=ep_contact_get_normal_x(global.world, contact)
normal_y=ep_contact_get_normal_y(global.world, contact)
normal=radtodeg(arctan2(normal_y,normal_x))

At first I thought it worked but that was far from the truth -_-

Essentially, horizontal collisions are backwards, so for instance, if (A) collides with the left of (B) it returns 0 when really it should return 180. Although diagonals and everything in between doesn't work, vertical collisions appear to work for some reason.

So..um..do you have any idea what the problem is? My friends and I have been wracking our brains for days and can't seem to figure out whats going on. I personally think my math is just wrong :I

I also have a question about collision filtering, I thought I understood it at first but apparently I don't :P
I'll save that for later though.

Thanks.

Matt13

Comment #44: Sun, 2 Oct 2011, 1:43 (GMT+1, DST)

Quote


Hello. I am having a problem with my current game. I am using ExtremePhysics 2.2 to simulate dead bodies. Every so often, the player activates a save station and it saves the game using the gamemaker function. When the player dies it loads the game. When i load the game, i get a Extremephysics error everytime. Somthing about an object not being found.

To try to solve this problem, i tried destroying the world befor loading, then after the loading block put create world. (something like this)

(if player is dead)
DESTROY WORLD
LOAD GAME
CREATE WORLD

I got an error that the world was never created. How do i automatically create another world when the game is loaded????

Please help

Matt

Gregoryogan

Comment #45: Thu, 6 Oct 2011, 6:32 (GMT+1, DST)

Quote


Hello!!

Hey i'm having some trubles here i'm trying to make a dynamic Body to move towards a point like

move towards a point mouse_x and Mouse_y, But that doesnt work, i tried to apply impulse its works but i cant reach the specific point like mouse_x and mouse_y.

Can you help please??

Greg

Maarten Baert

Administrator

Comment #46: Thu, 6 Oct 2011, 14:07 (GMT+1, DST)

Quote


@Solarboy: You can get perfect 'elastic' collisions by setting 'restitution' to 1 for both shapes. So I don't think you will actually need the angle. Anyway, it doesn't work because in GM the Y axis points down, not up. So arctan2 returns incorrect results. This should work:

normal=radtodeg(arctan2(-normal_y,normal_x))

I don't know how you did the actual mirroring of the angle, but this is what I would do:

new_direction = 2*normal-old_direction;

If you did something else, that might also be the cause :).

@Matt13: I created the functions ep_world_serialize and ep_world_unserialize exactly for situations like this. Basically you have to serialize the world right before you save the game, and destroy the world right before loading the game. When the game is loaded you should create the world again and unserialize it. I have never actually tried this with the built-in saving mechanism, though. Try this:

// create event
global.world_serialize = "";

// saving:
global.world_serialize = ep_world_serialize(global.world);
game_save();

// loading:
ep_world_destroy(global.world);
game_load();

// begin step event of the object with the highest depth (the controller):
if global.world_serialize!="" {
    global.world = ep_world_create();
    ep_world_unserialize(global.world, global.world_serialize);
    global.world_serialize = "";
}

Does this work for you?

@Gregoryogan: Try this:

var v, vx, vy, d;
v = 10; // this sets the (maximum) speed
vx = mouse_x-ep_body_get_x_center(global.world, body);
vy = mouse_y-ep_body_get_y_center(global.world, body);
d = sqrt(vx*vx+vy*vy);
if d>v {
    vx *= v/d;
    vy *= v/d;
}
ep_body_set_velocity_center(global.world, body, vx, vy, 0);

Last modified: Thu, 6 Oct 2011, 14:17 (GMT+1, DST)

Gregoryogan

Comment #47: Thu, 6 Oct 2011, 15:49 (GMT+1, DST)

Quote


Hey Maarten!

Hey that worked Thank you!!

Hey i think a lot of GM user uses this function to move objects around and even to follow another object when placed in the Step events so thanks to you i could make a function, if you are going to release a new version of the amazing engine you could add this with the update it would be a great help for the other users, what you think?

Thanks again!

Function ep_body_move_towards_point(x,y,velocity)

var v, vx, vy, d;
v = argument2; // this sets the (maximum) speed
vx = argument0-ep_body_get_x_center(global.world, body);
vy = argument1-ep_body_get_y_center(global.world, body);
d = sqrt(vx*vx+vy*vy);
if d>v {
vx *= v/d;
vy *= v/d;
}
ep_body_set_velocity_center(global.world, body, vx, vy, 0);

Solarboy

Comment #48: Sun, 9 Oct 2011, 9:12 (GMT+1, DST)

Quote


Oh man that works great, thanks! The reversed Y was what messed us up, otherwise we were much closer then I thought, literally the code was identical other then the negative sign :P

Again, thank you! Your the best!

A_d_y

Comment #49: Thu, 13 Oct 2011, 12:01 (GMT+1, DST)

Quote


i wanna rotate my boxchain :) how can i do that :) Actualy how can i update boxchain points.

Maarten Baert

Administrator

Comment #50: Thu, 13 Oct 2011, 12:20 (GMT+1, DST)

Quote


Quote: A_d_y

i wanna rotate my boxchain :) how can i do that :)

Just rotate the body.

Quote: A_d_y

Actualy how can i update boxchain points.

You can't, box chains are converted to normal box shapes when you call ep_body_boxchain_end. You have to write your own code if you want to change them afterwards.

Bavogames

Comment #51: Sat, 15 Oct 2011, 14:50 (GMT+1, DST)

Quote


Is there a way to create a damage system?
ex. detect collisions and their force and use the force to change the heath of the object(more force = more damage)

Drivinucrazy Games

Comment #52: Sat, 22 Oct 2011, 2:27 (GMT+1, DST)

Quote


Hey Maarten,

How do you get bodies to stop "squirming around" when piled up? I have a heap of boxes, and even with sleeping on, they don't want to stabilize.
These are my settings:

ep_world_set_settings(world,1/room_speed,20,10,0.5,0.5,0.1,0.5,1);
ep_world_set_sleeping(world,1,0.1,0,200,3);

Last modified: Sat, 22 Oct 2011, 2:31 (GMT+1, DST)

Maarten Baert

Administrator

Comment #53: Sat, 22 Oct 2011, 15:31 (GMT+1, DST)

Quote


Quote: Bavogames

Is there a way to create a damage system?
ex. detect collisions and their force and use the force to change the heath of the object(more force = more damage)

First read the tutorial about collision detection:
http://www.maartenbaert.be/extremephysics/tutorials/collision-detection/
When you've detected a collision, you can use ep_contact_get_point1_normalveldelta and ep_contact_get_point2_normalveldelta to get the impact velocity. You can also use the impact force, but I think it will look more realistic if you use the velocity.

Quote: Drivinucrazy Games

Hey Maarten,

How do you get bodies to stop "squirming around" when piled up? I have a heap of boxes, and even with sleeping on, they don't want to stabilize.
These are my settings:

ep_world_set_settings(world,1/room_speed,20,10,0.5,0.5,0.1,0.5,1);
ep_world_set_sleeping(world,1,0.1,0,200,3);

Disable sleeping and solve the stability problem first, and when that works you can try to enable sleeping again. Your values for stable_maxvel and stable_maxrotvel are way too high, that might actually make it worse. Sleeping generally doesn't make the simulation more stable, it just hides the problem :).

Try setting baumgarte_factor to 0, and make sure the coefficient of restitution of the boxes isn't too high.

Drivinucrazy Games

Comment #54: Sun, 23 Oct 2011, 1:01 (GMT+1, DST)

Quote


Quote

Disable sleeping and solve the stability problem first, and when that works you can try to enable sleeping again. Your values for stable_maxvel and stable_maxrotvel are way too high, that might actually make it worse. Sleeping generally doesn't make the simulation more stable, it just hides the problem :).

Try setting baumgarte_factor to 0, and make sure the coefficient of restitution of the boxes isn't too high.

Oh man, thanks. I set the sleeping values way down (10 and 1) and set baumgarte_factor to 0 and it's looking a lot more stable :D

Ninajejoe5

Comment #55: Wed, 16 Nov 2011, 17:15 (GMT+1, DST)

Quote


I just wanted to say i have had this dll for a while now, and i have always wanted to use it but could never get a grasp on it, i could understand it but i was like whoa complicated, i i finnaly said f it might as well just put the variables together like you said, and you know it's really not all that comlicated its acctualy pretty staight forward, so thanks man keep it up, this is really gonna help me make the kinda games i want to.

Write a comment