Extremephysics - 2d Physics Engine For Game Maker
#1021
Posted 05 February 2012 - 03:43 PM
#1022
Posted 08 February 2012 - 03:55 AM
thanks..
#1023
Posted 08 February 2012 - 05:40 PM
The player object has a simple dynamic EP_box body,but moves with GML... (x+=4 ect)
I want to update the position and rotation of the physics object based on the players x,y and image angle.
The issue im having, is that when ever i try to update the physics objects position, it seems to "lag" behind my player.
This lag is not related to the players x and y speed, and seems to be VERY random... sometimes quite extreme.
Any ideas? Should i be using a static body for my object??
#1024
Posted 08 February 2012 - 09:55 PM
Thanks!
#1026
Posted 12 February 2012 - 02:39 PM
Yes, if these platforms allow compiled code at all it should work (if you remove some parts like debug drawing). You have to recompile it of course.Hi i would like to know if it would be possible to use it on game maker studio to export all the required dlls for an exportable apk to work on android or ios.,
thanks..
You should do it the other way around. ExtremePhysics controls the object, so if you want the object to move you should move the body in ExtremePhysics (and the object will follow).Hello. Wonderful engine you have here. I have one small problem i hope you can help me with.
The player object has a simple dynamic EP_box body,but moves with GML... (x+=4 ect)
I want to update the position and rotation of the physics object based on the players x,y and image angle.
The issue im having, is that when ever i try to update the physics objects position, it seems to "lag" behind my player.
This lag is not related to the players x and y speed, and seems to be VERY random... sometimes quite extreme.
Any ideas? Should i be using a static body for my object??
If you want to 'teleport' the object to a new position you can use ep_body_set_position. If you just want the body to move, you should use ep_body_set_velocity (otherwise things like pushing other bodies won't work properly because the player is essentially teleporting into them instead of pushing them).
I guess it's possible, but it sounds very complicated. Splitting polygons is relatively easy, but merging takes a lot of processing time (it might be possible in C++, but GML will probably be too slow).In your destructible terrain demo you're using box shapes of varying sizes. Could that same effect be done with polygons on a fixed grid size (32x32 blocks), or would that be too slow? I'm basically looking for a way to dynamically merge/separate clusters of blocks as they are created/destroyed in a minecraft style system so that it can be as fast as possible. Polygons would allow me to add slopes.
Thanks!
Have you thought about merging the 32x32 blocks, but simply not merging the other shapes? It's not as good as actually merging everything, but it will merge all large areas of blocks.
Alternatively you can use something like box chains to trace the contour of the terrain, and simply merge adjacent boxes that have the same slope. That way you won't have anything on the inside of the terrain so it's very efficient, and it's not that difficult to program.
#1027
Posted 14 February 2012 - 10:05 PM
One approach I've developed lately has been to try and eliminate as many unnecessary game instances as possible while running the simulation. Usually every physics body has an instance attached to it in the game, and well this can help make it easier to manage objects it's a little wasteful. Specially with static objects. For example, your destructible terrain demo can have thousands of instances in it at once (even though it runs relatively fast.)
So I created a script that creates a single physics body and then adds static shapes to it based on the location of tiles it finds in the room. Now I've heard that lots of tiles can slow down your game, but their supposed to be much faster then instances. Here is the script and example file. Feel free to include it in any future releases of your extension.
//physics_tiles_create()
tile_size = 32;
tile_layer = 1000000;
body = ep_body_create_static(global.world);
for (yy=0; yy < room_height; yy+=tile_size)
{
for (xx = 0; xx < room_width; xx+=tile_size)
{
if tile_exists(tile_layer_find(tile_layer, xx, yy))
{
shape[xx/tile_size,yy/tile_size] = ep_shape_create_box(global.world,body,tile_size,tile_size,xx+tile_size/2,yy+tile_size/2,0,1);
ep_shape_set_collision(global.world,body,shape[xx/tile_size,yy/tile_size],1,1|2,0);
ep_shape_set_material(global.world,body,shape[xx/tile_size,yy/tile_size],0,0.1,0,0);
}
}
}Example file (gmk)My next goal is to find a way to optimize drawing even further by perhaps removing tiles altogether. I want to see if I can use surfaces to draw only the active part of the view in the room so I can add special effects and only render what you can see. I'm thinking I should be able to find where physics blocks are in relation to the view, and then be able to draw a sprite to the surface at their locations? Wish me luck!
Edit: Oh I should also say that the script here is a simplified version of the one I'm currently using. In my more advanced script each tile has it's own body and shape. I did this so I could use ep_body_get_x and ep_body_get_y for certain tasks.
Edited by IcyEye, 14 February 2012 - 10:14 PM.
#1028
Posted 21 February 2012 - 03:50 PM
I've tried out your extension and in principal it works fine. The problem is as soon as I save the project and reopen it, it seems Extreme Physics stops working. The functions are still recognized by Game Maker (as they are syntax highlighted), but when I look at for the local variables of instance the body variable I'm using it's 0. I did not change a single character of the script, but as soon as I reopen my projects it stops working. When I create a fresh new project and install Extreme Physics again it works as soon as I save and reopen the project... What am I doing wrong? I followed exactly the installation instructions provided in the readme of the dll. I'm currently using Game Maker 8.1 with HTML5 support on a windows 7 64 bit machine.
Cheers
#1029
Posted 22 February 2012 - 10:54 PM
I've never tested it with GM HTML5 (which I don't have). Does it work if you use GM8 of GM8.1 (i.e. without HTML5)?Hello,
I've tried out your extension and in principal it works fine. The problem is as soon as I save the project and reopen it, it seems Extreme Physics stops working. The functions are still recognized by Game Maker (as they are syntax highlighted), but when I look at for the local variables of instance the body variable I'm using it's 0. I did not change a single character of the script, but as soon as I reopen my projects it stops working. When I create a fresh new project and install Extreme Physics again it works as soon as I save and reopen the project... What am I doing wrong? I followed exactly the installation instructions provided in the readme of the dll. I'm currently using Game Maker 8.1 with HTML5 support on a windows 7 64 bit machine.
Cheers
#1030
Posted 23 February 2012 - 03:41 PM
Static wall object:body = ep_body_create_static(global.world);
shape1 = ep_shape_create_box(global.world,body,32,32,16,16,0,1);
ep_shape_set_collision(global.world,body,shape1,1,1|2,0);
ep_shape_set_material(global.world,body,shape1,0.2,0.4,0,0);
physics_object_set(body);
Robot Object:Information about object: obj_player
Sprite: sprite_Robot_Stand_1
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
execute code:
group = physics_get_new_group();
body = ep_body_create_dynamic(global.world,true);
// lower part
shape1 = ep_shape_create_box(global.world,body,64,200,32,16,0,1);
ep_shape_set_collision(global.world,body,shape1,1,1|2,group);
ep_shape_set_material(global.world,body,shape1,0,0.4,0,0);
ep_body_calculate_mass(global.world,body);
ep_body_set_gravity(global.world,body,0,platformgravity*2);
physics_object_set(body);
Destroy Event:
execute code:
ep_body_destroy(global.world,body);
Step Event:
execute code:
var left,right,jump,xvel,yvel,a,xfrom,yfrom,xx,yy,d,dist,xrel,yrel,f;
xvel = ep_body_get_xvel_center(global.world,body);
yvel = ep_body_get_yvel_center(global.world,body);
ww = 64;
hh = 200;
left = ((keyboard_check(vk_left) or keyboard_check(ord("A"))) and !ep_world_collision_test_box(global.world, ww, hh-1, x+ww/2-1, y+hh/2-0.5, 0, -0.1, 0, 2, group));
right = ((keyboard_check(vk_right) or keyboard_check(ord("D"))) and !ep_world_collision_test_box(global.world, ww, hh-1, x+ww/2+1, y+hh/2-0.5, 0, -0.1, 0, 2, group));
jump = ((keyboard_check(vk_up) or keyboard_check(ord("W"))) and ep_world_collision_test_box(global.world, ww-2, 2, x+ww/2 , y+hh+1 , 0, -0.1, 0, 1|2, group));
// move left/right
a = (right-left)*128;
xvel += max(-2,min(2,a-xvel));
// jump
if jump {
yvel = -30;
}
ep_body_set_velocity_center(global.world,body,xvel,yvel,0);
// shoot
if mouse_check_button(mb_left) {
xfrom = x+10;
yfrom = y;
xx = mouse_x-xfrom;
yy = mouse_y-yfrom;
d = sqrt(xx*xx+yy*yy);
xx /= d;
yy /= d;
dist = ep_world_ray_cast(global.world,xfrom,yfrom,xx,yy,1,1,group);
if dist=-1 {
dist = 10000;
} else {
a = ep_world_get_collision_body(global.world);
if !ep_body_is_static(global.world,a) {
xrel = xfrom+xx*dist-ep_body_get_x_center(global.world,a);
yrel = yfrom+yy*dist-ep_body_get_y_center(global.world,a);
f = 200000;
ep_body_apply_impulse_relative(global.world,a,xrel,yrel,xx*f,yy*f,0,false,true);
}
}
a = instance_create(16,0,obj_ray);
a.x1 = xfrom;
a.y1 = yfrom;
a.x2 = xfrom+xx*dist;
a.y2 = yfrom+yy*dist;
}
End Step Event:
execute code:
physics_object_update(body);
Draw Event:
execute code:
draw_sprite_corrected(sprite_index,image_index,x,y,image_xscale,image_yscale,direction,image_blend,image_alpha);
#1031
Posted 24 February 2012 - 04:40 PM
shape1 = ep_shape_create_box(global.world,body,64,200,32,16, 0,1);with:
shape1 = ep_shape_create_box(global.world,body,64,200,32,100, 0,1);And move the origin of your sprite. Does that fix it?
Alternatively, replace:
jump = ((keyboard_check(vk_up) or keyboard_check(ord("W"))) and ep_world_collision_test_box(global.world, ww-2, 2, x+ww/2 , y+hh+1 , 0, -0.1, 0, 1|2, group));with:jump = ((keyboard_check(vk_up) or keyboard_check(ord("W"))) and ep_world_collision_test_box(global.world, ww-2, 2, x+ww/2 , y+hh+1-84 , 0, -0.1, 0, 1|2, group));
#1032
Posted 25 February 2012 - 11:24 AM
var c;
for(c = ep_shape_get_first_contact(global.world, body, shape); c!=0; c = ep_shape_get_next_contact(global.world, body, shape, c)) {
b = ep_contact_get_body1(global.world, c);
if b=body {
b = ep_contact_get_body2(global.world, c);
}
hit = ep_body_get_uservar(global.world, b, 0);
switch (hit.object_index)
{
case obj_block: with (hit) instance_destroy();
}
}How would I do this correctly?I would also like to create an explosion that destroys objects that are very close and pushes ones that are farther away, but I really don't know the best way to go about doing this.
#1033
Posted 25 February 2012 - 06:18 PM
I just can't get the multipolygons to work.
I used the multipolygons example and tried to modify it to my point database, but it just wont work.
And then I get a error: A sub polygon is not convex. Is there a way of making non convex multipolygons?
I have a database of all the points.
points = 5
point[1,0] = 0 //this is point 1 x
point[1,1] = 0 //this is point 1 y
The object creation code I use looks like this: But it don't work.
ep_world_multipoly_begin(global.world,points);
c = 1 //current point / start point
repeat(points)
{
ep_world_multipoly_set_vertex(global.world,c-1,point[c,0],point[c,1]);
c += 1
}
ep_world_multipoly_end(global.world,true);
poly_first = ep_world_multipoly_get_first(global.world);
poly_last = ep_world_multipoly_get_last(global.world);
body = ep_body_create_dynamic(global.world,false);
for(i=poly_first;i<=poly_last;i+=1) {
shape = ep_shape_create_polygon(global.world,body,i,0,0,0,0.1);
ep_shape_set_collision(global.world,body,shape,1,1,0);
ep_shape_set_material(global.world,body,shape,0.2,0.5,0,0);
}
ep_body_calculate_mass(global.world,body);
ep_body_set_position(global.world,body,mouse_x,mouse_y,0);
ep_body_set_gravity(global.world,body,0,0.2);
Could anyone help me with a good multipolygon creating example?
Thank you in advance.
Edited by Universal_X, 25 February 2012 - 06:20 PM.
#1034
Posted 26 February 2012 - 09:21 PM
I did what you said to do, I changed the values and now the robot will jump properly. But when I make the height of the object larger than 200, it will not jump any more. How can I use any size I want?
#1035
Posted 07 March 2012 - 02:19 AM
What are the units you use for mass, distances and time? (Well, time, I can deal with it myself. But mass and distances I need to know what you based your code on.)
Edit: After thought, I need your time unit too.
Edited by dark_master4, 08 March 2012 - 12:22 AM.
#1036
Posted 08 March 2012 - 05:55 PM
It doesn't work because by destroying the instance, you're invoking the destroy event which destroys the body and also the contact c. So ep_shape_get_next_contact doesn't work anymore. It's not supposed to crash though, you should just get an error message ...I'm trying to destroy objects when they collided with other objects, but doing so inside a for loop causes errors.
var c; for(c = ep_shape_get_first_contact(global.world, body, shape); c!=0; c = ep_shape_get_next_contact(global.world, body, shape, c)) { b = ep_contact_get_body1(global.world, c); if b=body { b = ep_contact_get_body2(global.world, c); } hit = ep_body_get_uservar(global.world, b, 0); switch (hit.object_index) { case obj_block: with (hit) instance_destroy(); } }How would I do this correctly?
I would also like to create an explosion that destroys objects that are very close and pushes ones that are farther away, but I really don't know the best way to go about doing this.
The solution is to run
c = ep_shape_get_next_contact(global.world, body, shape, c)before you destroy the instance.
Non-convex polygons are supported. If you get that error message, this means the polygon was self-intersecting or not defined in clockwise order.Hi!
I just can't get the multipolygons to work.
I used the multipolygons example and tried to modify it to my point database, but it just wont work.
And then I get a error: A sub polygon is not convex. Is there a way of making non convex multipolygons?
I have a database of all the points.
points = 5
point[1,0] = 0 //this is point 1 x
point[1,1] = 0 //this is point 1 y
The object creation code I use looks like this: But it don't work.ep_world_multipoly_begin(global.world,points); c = 1 //current point / start point repeat(points) { ep_world_multipoly_set_vertex(global.world,c-1,point[c,0],point[c,1]); c += 1 } ep_world_multipoly_end(global.world,true); poly_first = ep_world_multipoly_get_first(global.world); poly_last = ep_world_multipoly_get_last(global.world); body = ep_body_create_dynamic(global.world,false); for(i=poly_first;i<=poly_last;i+=1) { shape = ep_shape_create_polygon(global.world,body,i,0,0,0,0.1); ep_shape_set_collision(global.world,body,shape,1,1,0); ep_shape_set_material(global.world,body,shape,0.2,0.5,0,0); } ep_body_calculate_mass(global.world,body); ep_body_set_position(global.world,body,mouse_x,mouse_y,0); ep_body_set_gravity(global.world,body,0,0.2);
Could anyone help me with a good multipolygon creating example?
Thank you in advance.
Replace 100 with yournewheight/2shape1 = ep_shape_create_box(global.world,body,64,200,32,100,0,1);
I did what you said to do, I changed the values and now the robot will jump properly. But when I make the height of the object larger than 200, it will not jump any more. How can I use any size I want?
I wrote a tutorial:Hi Maarten! I have a question for you as I'm trying to use the most realistic values possible with your engine:
What are the units you use for mass, distances and time? (Well, time, I can deal with it myself. But mass and distances I need to know what you based your code on.)
Edit: After thought, I need your time unit too.
http://www.maartenbaert.be/extremephysics/tutorials/unit-systems/
#1037
Posted 18 March 2012 - 02:36 PM
#1038
Posted 18 March 2012 - 02:58 PM
#1039
Posted 18 March 2012 - 03:01 PM
here is the topic i posted in the wrong place
Edited by 'tear, 18 March 2012 - 03:28 PM.
#1040
Posted 18 March 2012 - 03:53 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users









