Breakable Objects

Get help using Construct 2

Post » Mon Nov 28, 2011 6:21 am

I want to have a physics object break realistically when it collides with another physics object. Very similar to Angry Birds. The problem is that I would have to add one event for each possible case which could easily get to 20 events.

Also, how can I get it to play an animation instead of just disappearing?
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Wed Nov 30, 2011 11:37 am

Yup, was about to post this question too, anyone can help here?


Thanks in advance.
B
3
G
1
Posts: 3
Reputation: 581

Post » Fri Dec 30, 2011 12:15 pm

I'm very interested too...

Based on the mass and the velocity of two objects, how can I determine which of them will be broken when they collide? (like in Angry Birds and other similar games)

Thanks in advance, too!

Rag
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Fri Dec 30, 2011 12:34 pm

If you want to break object to two or three pieces you should create this pieces first. When you break this object spawn this three pieces.
B
94
S
19
G
34
Posts: 1,840
Reputation: 27,988

Post » Fri Dec 30, 2011 2:33 pm

Thx

But what I don't know is : how can I know when it is consistant to break on objet or another?

For example, in real life, if you throw a fragile object on a stone wall at high speed, this object will be broken and the wall won't be. But if you throw, on the same wall at the same speed, let's say... a canonball, the wall will be broken ! (eventually)

And if you throw the fragile object at low speed, it won't be broken.

Know what I mean? I'd like to understand and apply this consistency with C2.

Thanks in advance
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Fri Dec 30, 2011 2:49 pm

Well, you kinda wrote the solution yourself by explaining it

I haven't much experience on C2, but I think the method to C Classic is similar.

If:
objects speed is over XXX
object 1 and object 2 are colliding
object 1's private variable(fragile) = 1

then
object 1 = break.

That would be my approach.zyblade2011-12-30 14:49:48
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Post » Mon Jan 02, 2012 1:15 am

This is my attempt at making it decide whether an object should break or not:
http://dl.dropbox.com/u/52788071/break_events_01.png

So it adds the speed of both of the objects together and if it is greater than the breaking speed, it gets the angles that both are moving at as well as the angle between their coordinates. If at least two of those are the same (give or take 45 degrees), the object will break.
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Mon Jan 02, 2012 1:56 am

If we ask mister Physic, he will talk about kinetic energy (Ek)
Ek = 1/2 *mass*speed^2
So what you would want to know is what is the Ek applied to an object.
And based on it's fragility (which could be an instance variable) you could break it or not.
Well fragility... It could really be just Hit Point. This way you can hit the same object many times until it break.
Also, the mass would be another instance variable.
So we just need to know the speed of the first object relatively to the other one.
Well wait a minute

obj1 has an Ek1 ->   Energy impact = Ek1+Ek2   <- obj2 has is own Ek2

well it's true only for a frontal impact.
So how to evaluate non frontal impact?
You probably have to project the velocity vector of obj1 onto the velocity vector of obj2

Yeah I guess it would be like that:
[code]Sprite1: On Collision with Sprite2
   Local Variable v1X // Sprite1.Physics.VelocityX (for simplification)
   Local Variable v1Y // same
   Local Variable v2X // same
   Local Variable V2Y // same
   Local Variable v1   // Sprite1 velocity projected to Sprite2 velocity
   Local Variable v2   // Sprite2 velocity
   Local Variable ECollision //Energy generated by the collision
   //Simplification
   -> System: Set v1X to Sprite1.Physics.VelocityX
   -> System: Set v1Y to Sprite1.Physics.VelocityY
   -> System: Set v2X to Sprite2.Physics.VelocityX
   -> System: Set v2Y to Sprite2.Physics.VelocityY
   //we get (more or less) the Magnitude of the vector (v1X,v1Y) projected on v2
   -> System: Set v1 to -cos(angle(0,0,v2X,v2Y)-angle(0,0,v1X,v1Y))*distance(0,0,v1X,v1Y)
   //Magnitude of the vector (v2X,v2Y) (actual speed)
   -> System: Set v2 to distance(0,0,v2X,v2Y)
   //Energy of the collision
   -> System: Set ECollision to 0.5*Sprite1.mass*v1^2 + 0.5*Sprite2.mass*v2^2[/code]
Then you just have to use the value of ECollision as a Damage value. Decreasing HP of your sprites and breaking them if it's too high.
This calculation should also work if obj2 try to move away from obj1, the damage should be less than if obj1 is immobile.Yann2012-01-02 02:02:43
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests