How do I keep physics gravity while resizing a sprite?

Get help using Construct 2

Post » Thu Dec 22, 2016 6:46 am

I've looked all around and don't understand why gravity stops working when a physics object gets resized.

This capx I made has one event. If you disable it the sprites fall like a normal physics object would. Any ideas? Is this a bug or is this just how physics objects work? I'm using r239.

https://dl.dropboxusercontent.com/u/19590484/resizing%20physics%20objects.capx
B
6
S
3
G
2
Posts: 104
Reputation: 1,960

Post » Thu Dec 22, 2016 6:56 am

See Ashley's response here to a similar problem reported as a bug. Every time you change animation frame, or resize an object (as in your case), the physics body inside the physics engine has to be replaced.

The Physics behavior treats a change of frame as destroying the physics body and teleporting a new one in its place (to take in to account changing collision poly, size, origin etc). Therefore animating objects keeps destroying the physics body you're applying force to.
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,296
Reputation: 47,576

Post » Thu Dec 22, 2016 2:23 pm

Hey thank you for pointing me in the right direction.
B
6
S
3
G
2
Posts: 104
Reputation: 1,960

Post » Thu Dec 22, 2016 2:27 pm

Use a placeholder (invisible sprite) to keep the physics and your sprite as an image only.
Image
B
108
S
24
G
18
Posts: 1,376
Reputation: 22,830

Post » Thu Dec 22, 2016 8:38 pm

Any recalculation of the collision polygons (sine, scaling, animation) will give you a memory related java error, when physics is used, anywayz.
Depending on how many affected objects, the error pops up in 1 minute or 20 minutes later.

Try it, give the objects in your capx a sine (on size) behaviour. Empty event sheet.

javascript-uncaught-abort-crash-physics-behaviour-js_t163513
physics-error-and-crash_t150137


Try
behavior-chipmunk-physics_t110815
?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Dec 22, 2016 10:33 pm

You can also save the velocity and angular speed to variables before setting the size and setting the velocty from the variables after.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Fri Dec 23, 2016 6:23 pm

@R0J0hound

I tested his capx with your excellent Chipmunk Physics as engine. The objects fall and collide while resizing. Even with a sine behaviour (size) attached. So it works flawless as one would expect.

But now, after your suggestion, i doubt my suggestion. Does Chipmunk has the same (or other) problems with recalculating polygons ? (As in animations by instance)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Dec 24, 2016 12:35 am

It's just an alternate idea of one doesn't want to use a third party behavior. Chipmunk does also recreate the shape but the velocity is retained. There isn't a crash if you do it continuously. All the old shapes should be cleaned up by the garbage colllector.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853


Return to How do I....?

Who is online

Users browsing this forum: angryscientist, Exabot [Bot] and 25 guests