How do I replicate the bounce off behaviour with events

Get help using Construct 2

Post » Mon Jan 18, 2016 9:50 pm

So bullet has a nice behavior where it bounces off an object, using its angle of motion and the angle of the object that it's bouncing off.

However I've been trying to make a pseudo-3D game in which I've determined, in order for physics to not be destroyed too badly, I need to keep the x/y/z coordinates + angle of motion of the objects in variables, then pass them through a relocation pass before the objects are drawn to the screen.

This means that I can't use the bullet behavior, since it doesn't update the object variables which state where it actually is. The vast majority of the behavior is easy to implement via events, but the bounce off function is notably more complex. For example, how do you find the angle of the object it's bouncing off of if the bounding box of the object being bounced off isn't square?
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Tue Jan 19, 2016 1:44 am

You could still use the bullet behavior. Just have it disabled until you want to bounce. Then when you want to use the bounce you enable it, set the speed and angle of motion from your variables, use the bonce action, then set your variables from the bullet's speed and such, and finally disable the behavior.

If you want to do it with events, here's one way:

1. when the object collides with a wall, move it backwards till it isn't with a loop.

while
object is overlapping wall
--- object: move -1 pixel at angleOfMotion degrees

2. Next we need to find the angle between the object an the wall. One way you can approximate this is with detectors sprites or checking if points around the object collide with walls.

3. Then you can bounce by setting the angleOfMotion to 2*normal+180-angleOfMotion.

https://dl.dropboxusercontent.com/u/542 ... ounce.capx
B
89
S
30
G
95
Posts: 5,155
Reputation: 63,446

Post » Tue Jan 19, 2016 9:30 pm

Thanks, this looks good! Now I just need to make a few minor modifications to deal with a psudo-3D and I'll be good to go.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062


Return to How do I....?

Who is online

Users browsing this forum: Ajbael, ColombageEnPLS and 9 guests