How to draw objects and apply physics to it

Get help using Construct 2

Post » Sun Sep 04, 2016 5:35 am

Hi guys, Am complete beginner to construct 2. I want to develop a platform game where players will draw objetcs (basic shapes) and physics will be applied to it.
I found similar drawing and physics game: "http://armorgames.com/play/4673/test-pilot".
If anyone can tell where to get started and is it possible in construct 2 or not, it'll be great.

Thanks
B
3
Posts: 3
Reputation: 181

Post » Mon Sep 05, 2016 6:29 am

There is nothing in place to help with that. With the physics behavior the shapes need to be defined in the editor before the game is run. You could use the canvas or paster plugins to draw the object though.

One idea could be to build the shapes out of a bunch of simpler objects and join them together with joints, but that does have some issues. Namely objects joined together with joints behave a bit spongy.

A better solution is to work with the physics engine at a lower level using javascript, although you can't really do this along with the physics behavior. More on this in a moment.

The basic flow of your game would be to:
1. when you draw the shape a list of points is made.
2. Those points make up a polygon. This needs to be converted to a list of triangles or at least convex polygons. This is mainly for the physics engines which generally don't work with concave polygons.
3. find the center of mass by averaging the point locations.
4. create the physics object with that shape.

That may vary depending on what a given physics engine does for you.

Here's one possible example of using javascript to access a physics engine instead of using the behavior:
https://www.dropbox.com/s/314g422gfjlv2 ... .capx?dl=1
/5426011/examples34/jsPhysics.capx


On another note you did say simple objects. You probably could use some gesture recognition to see if the object is close to a circle, square or triangle. Then add a sprite with that shape and size and orient it to approximately match the area drawn. The gesture recognition is something a plugin may be able to help you with, or maybe even some other capx on the forum.
Last edited by R0J0hound on Mon Jul 17, 2017 4:00 pm, edited 1 time in total.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Sep 06, 2016 8:11 am

Message: vinigames can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
R0J0hound wrote:There is nothing in place to help with that. With the physics behavior the shapes need to be defined in the editor before the game is run. You could use the canvas or paster plugins to draw the object though.

One idea could be to build the shapes out of a bunch of simpler objects and join them together with joints, but that does have some issues. Namely objects joined together with joints behave a bit spongy.

A better solution is to work with the physics engine at a lower level using javascript, although you can't really do this along with the physics behavior. More on this in a moment.

The basic flow of your game would be to:
1. when you draw the shape a list of points is made.
2. Those points make up a polygon. This needs to be converted to a list of triangles or at least convex polygons. This is mainly for the physics engines which generally don't work with concave polygons.
3. find the center of mass by averaging the point locations.
4. create the physics object with that shape.

That may vary depending on what a given physics engine does for you.

Here's one possible example of using javascript to access a physics engine instead of using the behavior:
https://dl.dropboxusercontent.com/u/542 ... ysics.capx


On another note you did say simple objects. You probably could use some gesture recognition to see if the object is close to a circle, square or triangle. Then add a sprite with that shape and size and orient it to approximately match the area drawn. The gesture recognition is something a plugin may be able to help you with, or maybe even some other capx on the forum.



Thanks a lot.
Yes shapes are basic (Circle, Rectangle, Triangle or upto 5 faces max).
Since, shapes has to be defined, is it possible that through canvas or paster, player defines a shape. There will be start button, then once player presses it, those shapes will be given physics behavior. Then some simulation happens. Can this be done ??
B
3
Posts: 3
Reputation: 181

Post » Wed Sep 07, 2016 5:59 am

All the paster and canvas give you is an image. There collision shape is fixed as a box.

Physics will have to done in another way. The example above is one, making a bunch of different sized sprites beforehand is another I guess.

In short, basically anything can be done. In this case it's not something that's not made simple with existing things in C2 so instead you have to use some inginuity to get it working.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Wed Sep 07, 2016 8:25 am

Have you seen this, @vinigames ?
plugin-polygon-update-2013-04-23_t77970
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Wed Sep 07, 2016 4:17 pm

Thanks a lot @R0J0hound and @CloveltOc.
Polygon is interesting for what I'm doing. As R0J0hound suggested will have to work in JavaScript or underlying layers. With Polygon plugin, I must be able to achieve what I intend to do.
B
3
Posts: 3
Reputation: 181

Post » Wed Sep 07, 2016 4:32 pm

I have to check this out. I was trying to make something similar, on touch draw a dot. On hold every x seconds draw another. On release set them to "on"... this makes loads of physics balls appear and fall independently .. pin does nothing for physics objects.haven't tried joints however, would a joint connecting each joint to the rest make this more solid perhaps?
B
9
S
3
Posts: 102
Reputation: 987


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 12 guests