Custom Movement and Collisions, I have only one side working

Get help using Construct 2

Post » Wed Nov 18, 2015 9:47 pm

I'm having trouble making my own collisions/bouncing with the custom movement behavior.

I have the ship bounce against a wall and when it bounces on the left and right sides the bouncing angle looks correct, but top and bottom collision the angle is wrong and the ship just reverses.

Here's my code:
Image

If I swap the order of the two events in the collisions group, then top and bottom work while left and right don't. I'm kinda stumped.
Follow me on Twitter @evgLabs
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

Post » Thu Nov 19, 2015 3:39 am

I think you need to detect which side is being collided with for it to work right.
Maybe you could do something like this?

Sprite on collided with tiledbg

Sprite.y<tiledbg.top
Or
Sprite.y>tiledbg.bottom
> bounce vert

Sprite.x<tiledbg.left
Or
Sprite.x>tiledbg.right
> bounce horz


A more robust way could be to compare angles like

Angle(tiledbg.x,tiledbg.y,Sprite.x,Sprite.y) is within 45 degrees or 0
> bounce horz


Anyway just some ideas
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 38 guests