2 Sprites collision problem

Discussion and feedback on Construct 2

Post » Mon Dec 05, 2016 1:07 pm

Hey, I have a character made of 2 150px by 150px sprites and I want to move him on a grid, so I tried this:
Image

Basically, when I push "A" or Left Arrow, I move the bottom half 150px to the left (And since the top half will be pinned to the bottom half - 150px in the Y direction, it will move the top one too)

Then I check if the bottom half is overlapping the sprite "Ground" (So it would not go trough it) and if it is, I would add 150px to the bottom half, moving it back to it's place.


The problem comes when I apply the same code to the top half, but this time it does not work...
I also tried: If Bottom Half is overlapping Ground|
or | => then Bottom Half set X to self.X + 150px
If Top Half is overlapping Ground |
But this didn't work either...

What am I doing wrong?
(Here is the capx: https://www.dropbox.com/s/b1lp1puv1i81t ... .capx?dl=0)
ImageImageImageImage
B
30
S
9
G
7
Posts: 262
Reputation: 5,646

Post » Mon Dec 05, 2016 1:34 pm

I think you are not particularly doing something wrong, I just think C2 does not register yet the overllap, after muliple attempts that is the conclusion I am coming to.

I used another method, using the might of overllaping at offset, hope it works fine for your purpose: https://1drv.ms/u/s!AjkoCSebIn9JjCEO0d_UMx6pohZh
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Dec 05, 2016 2:36 pm

I don't understand, you don't want the character to be able to move if the top half is next to a wall, is that right?
So you shouldn't say "if top half is overlapping ground -> move left", you should say "if top half isn't overlapping ground on the left -> move left".

In this case you should use "is overlapping at offset".

You're also checking and moving for both bottom and top half. You're basically saying "if bottom part is overlapping ground and player presses left -> move left -> then check if the top half part is also overlapping ground -> move left again".

If you're trying to make it so the both parts can only move when there's no ground on where they are trying to move, you should do this:
Image
B
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » Mon Dec 05, 2016 4:54 pm

Aphrodite wrote:I think you are not particularly doing something wrong, I just think C2 does not register yet the overllap, after muliple attempts that is the conclusion I am coming to.

I used another method, using the might of overllaping at offset, hope it works fine for your purpose: https://1drv.ms/u/s!AjkoCSebIn9JjCEO0d_UMx6pohZh


andreyin wrote:I don't understand, you don't want the character to be able to move if the top half is next to a wall, is that right?
So you shouldn't say "if top half is overlapping ground -> move left", you should say "if top half isn't overlapping ground on the left -> move left".

In this case you should use "is overlapping at offset".

You're also checking and moving for both bottom and top half. You're basically saying "if bottom part is overlapping ground and player presses left -> move left -> then check if the top half part is also overlapping ground -> move left again".

If you're trying to make it so the both parts can only move when there's no ground on where they are trying to move, you should do this:
Image


Thank you very much for the help, guys!
I did not know that overlap at offset was a thing =D

I was first moving the player and then checking to see if he was overlapping with the ground (and if he was, I would move him back)
ImageImageImageImage
B
30
S
9
G
7
Posts: 262
Reputation: 5,646


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 14 guests