Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / best way for physical destruction

Author
Message
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Feb 2020 01:42
what is the recommended technique to create sprite destruction physics in AppGameKit?

At the moment what I'm doing is dividing a sprite into small parts in static mode and when an object comes into contact, that static part changes to dynamic mode
some very old games actually use a similar method, however this is not perfect



I already did some research, I already know the existence of memblocks, but it’s a little complicated to apply physics into this.

it would be fun if there is a command that can cut 1 sprite to 2 and apply physics to those 2 new sprites.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 01:48 Edited at: 21st Feb 2020 01:49
What happens if they're all dynamic to start with?
PS: Is this like a rampage type game?
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Feb 2020 02:13
if all objects had to start in dynamic mode, sometimes one of them can fall by it self and then everything falls.
in terms of performance I didn't notice any differences, it's always 60fps


honestly I'm still not sure what kind of game it is but it is possible to be something close to that, or at least something with buildings to destroy

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Feb 2020 03:04
I think you have done well with the way your doing it

Quote: "if all objects had to start in dynamic mode, sometimes one of them can fall by itself and then everything falls."

is it possible that they are positioned one pixel off at start.

In a 3D bowling game had alsorts of issues setting the pins into a position that didn't have that effect as they were dynamic


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 03:19
Have you tied using a circular shape as your wrecking instrument?
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Feb 2020 03:32 Edited at: 21st Feb 2020 03:36
yes i tried with different shapes




if I increase the size of the parts to three times the problem is solved, but the effect is not so fun.

i will try to do a sprite shatter system, there are some old techniques for faking images shattering on games, but I don't know if I'll be able to do this very well
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 04:13
It looks great! I'm sure it will make a great game
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Feb 2020 05:53 Edited at: 21st Feb 2020 06:04
I think this should help
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsMass.htm

try and set the mass three times normal

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Feb 2020 06:49 Edited at: 21st Feb 2020 06:55
I never had much success with the mass but I believe this is kinda what you want to achive
and mass is dependant on physics scale

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 06:52 Edited at: 21st Feb 2020 07:00
Maybe try this;
1. Use your original approach with the static shapes changing to dynamic shapes when in contact with the wrecking ball (Make it a circle)
2. When the sphere comes in contact with a block change it to dynamic BUT MAKE IT A SEPARATE GROUP, separate from the wrecking ball AND ALL OTHER STATIC SHAPES
3. Make sure it's depth is in front of all other static shapes and the ball
4. You may need to add a little force to it so it pops! (Calculate the angle of force from the center of the wrecking ball to the center of the block). Or just give the wrecking ball a lot of restitution)

I think things should fly around quite well then, very satisfying!!
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Feb 2020 19:10
and then with a bit of particles to make it more cool too.

and what about shaders? i think some fun things can be done on this
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Feb 2020 19:35
I just had an idea, what if I were to use joints?


connect sprites and be able to break these joints to create destruction physics.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 20:16
Joints would be interesting. It would keep the shape fairly solid and over hanging elements would collapse.
I'm looking forward to seeing what you do with this!!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 21st Feb 2020 21:10 Edited at: 21st Feb 2020 21:17
perhaps any sprite without a sprite beneath it should also be (or have a chance to be) triggered - so once you destroy the side the top will also fall.
give each "triggered" sprite a chance to trigger it's neighbors for more varied destruction rather than straight sides - perhaps the higher the sprite the higher the chance to trigger = wider base & narrow top
remove collision between the "player" and the "triggered" sprites so that you can more easily pass through to the sprites that are still "intact" - perhaps only do this for sprites touching the player at time of impact, that way you can still have sprites fall and bounce off the player but the ones in the way will not stop the destruction as much
all sprites without any neighbors should always be "triggered" to stop any floating remains (if you go with the random chance approach)
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Feb 2020 21:33
maybe a crane with a wrecking ball would look good and be fun
points for the amount of destruction

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Feb 2020 21:37 Edited at: 21st Feb 2020 21:39
Is there anyway to return all contacts for a sprite without having to make it dynamic? Possibly outside the physics system
@smallg @fubs both great ideas
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 22nd Feb 2020 01:55
yes, they are good ideas and can solve future problems.



I am currently trying to connect each part like this.



and I'm failing spectacularly


I am using Distance Joint but I am discovering that this may not be the best choice
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Feb 2020 02:09
I think a shader may be the solution, then use physics for the debris
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Feb 2020 04:57 Edited at: 24th Feb 2020 05:00
there are clearly improvements



but the physics continue to "dance"
https://i.imgur.com/s8tbXkU.mp4
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 24th Feb 2020 10:35
that's looking much better
try adjusting the dampening value up or perhaps the restitution value down
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Feb 2020 13:59
I tried and it didn't work and I tried to decrease the mass of the objects as it went up, it didn't work either.


sprites are overlapping
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Feb 2020 14:48
is there any way to check if a sprite is dynamic or static? a "GetSpritePhysicsMode" command or something
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Feb 2020 16:40
Quote: "it would be fun if there is a command that can cut 1 sprite to 2 and apply physics to those 2 new sprites"


Like This ?

Or click on the third icon in my signature.

Interesting thread by the way...watching this.
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Feb 2020 17:15
yes, similar to that.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th Feb 2020 18:02
Slice wise is very clever and no idea how that works

I did make a shatter sprite routine that basically breaks a sprite up into many squares
and when the person hits the space bar it sends all the pieces off in random direction

but you could use a routine that divides the building sprite into many parts and then
apply your break up routine with physics after

Not really what you need but does show how you can separate one sprite into many

Shatter Sprite ------if you want to try using the image I have works best for the test
https://forum.thegamecreators.com/thread/222027?page=3

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Feb 2020 18:33 Edited at: 24th Feb 2020 18:55

I Have two version one in which I use memblocks to remove the other side of the two new sprites and one in which I use a clipping shader and render image to create the two new sprites.
But at the end the important part is to calculate where to make the cut for a sprite which isn't rotated and positioned.
I just use y=m*x+b for the cut and calculate the m and b for a non rotated sprite in relation to the rotated sprite I want to cut: you can see that in the top left corner.

Seems you want to have something like notia did for their physics system:


I also have such a pixel sand simulation thing somwhere...really neat.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 24th Feb 2020 20:13
is the wobble since you added hinges? is there a way to reduce the "spring" value?

perhaps you can set them inactive till the player gets closer as a quick fix
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Feb 2020 20:48
Did you try the CreateWeldJoints ?
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Feb 2020 21:54
SetSpriteActive did not work, but it gave me an idea


CreateWeldJoints gave the same result, but there were improvements.

is there any way for a dynamic object to stand still?
totally immobile as if it were a static object.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 25th Feb 2020 12:59 Edited at: 25th Feb 2020 12:59
Quote: "is there any way for a dynamic object to stand still?"

SetPhysicsSleeping( mode ) didn't find a command to set a single sprite to sleep, so you'd somehow slow down the sprite until the system thinks its worth setting it to sleep.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 25th Feb 2020 19:41
Quote: "is there any way for a dynamic object to stand still?"

yes, set sprite active is the way so i guess the joint is taking over and moving it then

did you try dampening the joint?
also daft question but i assume you have the joint set to allow collision between the 2 sprites right?
CreateDistanceJoint( iJointIndex, iSpriteIndex1, iSpriteIndex2, x, y, x2, y2, colConnected )
Quote: "colConnected - Set whether the two sprites connected by the joint can collide with one another, 0=no, 1=yes."
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 25th Feb 2020 20:46 Edited at: 25th Feb 2020 20:46
Quote: "yes, set sprite active is the way so i guess the joint is taking over and moving it then"


It will wake up if something comes in contact though. Which is always true because of the blocks above it
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 03:38 Edited at: 26th Feb 2020 03:40
It works! no more wobble and sprites are resting and waiting for collision.

I changed some things, put the joints to the center of the sprite and used SetJointDamping



But i think i found some bugs on AGK
it's rare, and it only happens when the computer is under some stress but the physics load like that





and when moving the window, dynamic objects that are activated have movement.
https://imgur.com/L2cFIbp


And one more thing, how can I see if the dynamic sprite is resting?
it's because of this
I don't want the player to see the physics to prepare until they rest.

I want to put a loading screen and only then show the level when I know these dynamic objects are resting.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Feb 2020 03:40
Maybe check their velocity.
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 03:44
i forgot about that
yeh, that works too.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Feb 2020 03:45
Do you just move the large rectangle or apply forces to make it move?
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 03:46
apply forces with SetSpritePhysicsVelocity
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Feb 2020 04:33
What if you make the joints reflect what would be the underlying structure of the building.
Maybe save a little processing
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 26th Feb 2020 07:32 Edited at: 26th Feb 2020 07:48
here's my 2 cents worth of fun beginning with all static boxes and replacing them with dynamic ones based on impact while the static boxes help maintain stability until it's time to topple things; LMB to shoot:



play with:
threshold# = 1.5
shotforce# = 500.0
shotsize# = 30.0
&
SetSpritePhysicsFriction(new,0.3)

otherwise, i only skimmed through the above and don't know your real goal but i wouldn't mess with dampening, mass, etc, too much on the blocks. i've only played with friction and the physics scale (to get more velocity/effect for the shot) and i think the idea could provide a different base for you to tweak.

the joints could be doing the same/similar, for that matter. i haven't tried anything but this method (and i've had enough fun with the idea so probably won't be), though my first inclination was to break a single box into smaller quads/tris using chain shapes which shouldn't be too terrible since you can keep track of the verts easy enough (i see similar notion mentioned above re: slice-wise).

meanwhile, the code can optimized. ie, u could keep track of which static boxes were already replaced with dynamic ones (and see if checking is more efficient than just replacing them, over and over), etc.

bonus fun: try to flip boxes into gaps to reinforce the structure vs bringing it down. was a good 2 minutes of additional entertainment
extra bonus fun: start shots from within the structure

OUCH:
i just read the initial post...
Quote: "At the moment what I'm doing is dividing a sprite into small parts in static mode and when an object comes into contact, that static part changes to dynamic mode"

i was watching this thread on my TV's browser and was really just looking at the GIFs. sorry for re-inventing your wheel (and probably not helping much)
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 14:10
that is actually very good, I think I can use some ideas.
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 16:03 Edited at: 26th Feb 2020 16:04
after some tests i realized that joints have a lot of problems when they are at low frame rate.

this explains why sometimes this happens when the game starts
https://i.imgur.com/YlVxQQZ.gif
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 17:17 Edited at: 26th Feb 2020 18:08
I found a way to fix this using StepPhysics
like this StepPhysics(1.0 / 60.0)

but still not perfect
under +-10fps this is still happening

but it is not as chaotic as before


Edit:
it's solved,
found this https://forum.thegamecreators.com/thread/204311
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 26th Feb 2020 18:29 Edited at: 26th Feb 2020 18:31
more specifically this post by Paul - very handy to know, thanks
i'm curious why you'd only get 10fps on that example though, are you running it on a calculator or something?
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 26th Feb 2020 18:46 Edited at: 26th Feb 2020 18:46
I limited it to see if the problem was because of the low frame rate, because when the game starts the frame rate starts at 0 and that explains why everything is so broken.

so I started to test with lower frame rates and normally under 30 that problem was common
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 27th Feb 2020 15:22
I hadn't noticed, but when I turned off the debug I noticed that the parts don't stick together, they are at rest. No shaking.
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 27th Feb 2020 23:28
I noticed that the shape of the collision is made from the outside. (+1 pixel of the sprite size)
instead of this

I did this and solved the problem



but now this has happened and I don't know why.

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Feb 2020 03:29
What is the size of each block?
is it a power of 2? or atleast an even number

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
6
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 28th Feb 2020 04:23
it's 20x20



so far this is what has been done.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Feb 2020 04:58
Its looking good

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Feb 2020 20:48
That looks very good. What if you had joints from the base to the ground?

Login to post a reply

Server time is: 2024-11-22 10:55:51
Your offset time is: 2024-11-22 10:55:51