Distance

Get help using Construct 2

Post » Sat Feb 23, 2013 12:35 pm

Hey people

I am making a system where if the Player is close enough to a chest, he can access it. I've tried a lot of stuff, but i can't get it working - only on the X axis. I have an event like this:

When [Chest] left clicked
[Player] X > Chest.X+250
________________________
Set [Chest] animation frame to 1
Set Steak position to Chest.Y-30, Chest.X

..that works, but if i do like this:

When [Chest] left clicked
[Player] X > Chest.X+250
[Player] Y > Chest.Y+250
________________________
Set [Chest] animation frame to 1
Set Steak position to Chest.Y-30, Chest.X

..it won't work properly.

I know it sounds pretty weird, i've uploaded my .capx so you can look at it: http://www.mediafire.com/download.php?6775mlarzl1z6y4

I just need the player to only access the chest when he is 250 pixels near it. Both on the X and Y axis.

Thank you,
- CX05

B
5
Posts: 55
Reputation: 585

Post » Sat Feb 23, 2013 1:08 pm

Well, as I know;

player.x should be lesser than chest.x + 250
and player.x should be higher than chest.x -250

player.y should be lesser than chest.y + 250
and player.y should be higher than chest.y - 250

and for exact calculation you should add or subtract chest.width and chest.height

Also as I know;

you can use and invisible sprite where chest is located which has 500 width and 500 height. So you can use, if chest clicked, if player collides with invisible sprite. than open chest.

Spider_hip2013-02-23 13:10:26
B
7
S
1
G
1
Posts: 76
Reputation: 904

Post » Sat Feb 23, 2013 1:31 pm

Thank you, i'll try it when i get time.
B
5
Posts: 55
Reputation: 585


Return to How do I....?

Who is online

Users browsing this forum: jul, TELLES0808 and 22 guests