How to handle collisions outside of physics with bounce?

Get help using Construct 2

Post » Mon Jan 18, 2016 2:55 am

I am unsure how to do this, I am trying to use the custom movement to handle simple collisions with bounce, I know I could make something using trigonometry but last time I did something with manual physics it always gave me some performance issues. And I ended up going back to physics.
B
5
S
1
Posts: 68
Reputation: 515

Post » Mon Jan 18, 2016 9:51 pm

A bounce is basically done after a collision. Basically the steps are:
1. check for collision
2. resolve the collision by moving the object out of the other so it's just touching
3. find the angle of the edge of the object where the object's touch. This is the collision normal.
4. using the normal calculate the new velocities. This can be done with the angleOfMotion and the normal angle, or with the xy components and some vector math.

2 and 3 are the more involved ones. The simplest for 2 would be to just move the object backwards till it's not colliding. Calculating the normal with 3 can either be done with detector sprites to get a good approximation or you can do some math with the object's geometry (typically polygon or circle) and calculate a exact normal. Another way to handle both is to use SAT (separating axis theorem).
B
88
S
30
G
89
Posts: 5,104
Reputation: 60,319

Post » Tue Jan 26, 2016 1:21 am

well, I tried to do it but it will take more work, ive placed it to the side for now as it was giving me a headache.
B
5
S
1
Posts: 68
Reputation: 515

Post » Thu Mar 17, 2016 12:13 pm

I too would love to see an example for this.

In my case, I am trying to simulate gravity (without using physics) for a football object.
Thus, when the pointy side of ball touches the "ground" it surges and swirls forward (or slowly rotate backward-when .dx is slow) + loses momentum till it halts, much like when using physics.
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Fri Mar 18, 2016 3:04 am

@bloodshot
You can search my posts and I have made several different examples of doing physics with events. None are comprehensive, instead they focus on doing certain things.

In the example you're giving it's probably easier to use the physics behavior instead somehow. Unless you have a convincing reason not to.

But hey, if you really want to you can do it yourself and the rules above would work somewhat. It becomes a little more involved since the football rotates. As part of resolving the collision you'll want the point and normal of collision (you can have multiple points with complex terrain). The next but gets slightly more involved. Basically you apply an impulse at that point onto the ball which will result in linear and rotational motion. You'll also want to consider motion perpendicular to the contact normal and apply a friction impulse. There's guides elsewhere online that have the formulas you'll need.
B
88
S
30
G
89
Posts: 5,104
Reputation: 60,319

Post » Fri Mar 18, 2016 7:58 am

@R0J0hound Thanks!
Catching up to speed with your [BEHAVIOR] Chipmunk Physics. Perhaps this is what @Itenimum1 is looking for.
B
15
S
7
G
34
Posts: 55
Reputation: 18,478


Return to How do I....?

Who is online

Users browsing this forum: mekonbekon, RaiSen and 6 guests