How do I determine if an object is hitting a wall/ground?

Get help using Construct 2

Post » Mon Jun 08, 2015 7:32 pm

Using the physics behavior , how can I determine whether or not the player is hitting the side of object, or the top of the same object? I want to have the player take damage when he hits the floor or the top of an object, but not the sides. If you were wondering, the character is a physics rag-doll, and is completely controlled by the physics behavior, so i need to operate within the physics behavior. Is there any way? I can elaborate if asked, or post a .capx if needed.

Thanks.
B
8
S
2
Posts: 39
Reputation: 604

Post » Mon Jun 08, 2015 8:16 pm

Well, you can do that in two different ways.

If the player is overlapping the object you can compare player coordinates with the object coordinates and with this determine if the player is by the side of the object or above it or whatever.
However doing this requires a lot of testing and your game my get little buggy depending on the size of the sprites and speed they're moving.

The other way is to create invisible and objects and attach them to the visible object. Note that these invisible objects should be smaller than the first one, and they should be at least 1 or 2 pixels beyond the are of the visible one.
So you will check the player collisions to the invisible objects instead of the visible one. If the player collides with the invisible object attached to the left side of the visible one... then the player is colliding on the left.
This will make your codding easier and the game will run smoothly and with less bugs, whoever creating too many objects on a single layout will slow down your game performance
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Mon Jun 08, 2015 8:26 pm

Thank you, I never considered that. I was busy trying to think of something I could do strictly with coding, I really appreciate it. :)
B
8
S
2
Posts: 39
Reputation: 604


Return to How do I....?

Who is online

Users browsing this forum: evillair, lordsas, Matei511, tarek2 and 65 guests