How do I (In Description)

Get help using Construct 2

Post » Tue Apr 18, 2017 12:32 am

So I have an invisible 1x1 sprite that freezes the player when the player collides with it. This is done so that it looks like the player is interacting with the block below the sprite. What I really need, though, is for the player to stop to where it is perfectly lined up with the block, not off to the side. To clarify, both the player and the block are both roughly 32x32, so I need the player to freeze right when it is parallel with the block.

TLDR; read last sentence
B
8
S
1
Posts: 20
Reputation: 440

Post » Tue Apr 18, 2017 12:41 am

The problem is your player sprite does not necessarily move 1 pixel at a time, so it is hard to get that sort of precision. The solution is to add an action to move back to where it should be on the same tick that it passes beyond where you want it to be. As long as it is in the same tick, you shouldn't visually see the player ever going past the stopping point to begin with.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446

Post » Tue Apr 18, 2017 3:40 am

Thank you for the reply. However, your solution doesn't completely fix my problem. The block that the player is passing over can be approached from the left, right, and above. Thus, I would have to account for all three of these directions, which to my understanding can't be performed by your method because your method assumes that the player is coming from one direction only. Also, I cannot use coordinates because there are multiple of these objects throughout layouts and I am attempting to write an event that would cover all instances.
B
8
S
1
Posts: 20
Reputation: 440

Post » Tue Apr 18, 2017 4:34 am

I can imagine using the invisible sprite to set a state flag that determines which side you're approaching from upon colliding with it.

How exactly do you want the player to behave if approaching from the top? I'm assuming this is a platformer. If you land on the block from above does the player get shifted to align with the block, stuck in place where they land, or not stuck until they try to walk past the middle? Or does the block freeze them in the air if they try to jump over it?
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446

Post » Tue Apr 18, 2017 5:55 am

Seems like all you need is a way to pick the correct instance of the object you want to move/freeze the player to. So either some condition that picks only the relevant object or just using for each object to go through all of the objects should work if you really need the invisible sprite you could create a container with the invisible and not invisible object and use instance variable to store the IID of the visible thing so you can teleport player to it after collision.
capx with 4 ways to do it
B
17
S
6
G
1
Posts: 41
Reputation: 1,725

Post » Tue Apr 18, 2017 10:24 am

You could check:
if distance(player.X,player.Y,object.X,object.Y)<variable:

set player position to (object.X,objectY)
set movement to zero (i.e. stop inputs, bullet behaviour, whatever)

variable would be whatever the maximum distance player can travel in 1 tick, to ensure you catch it (in fact I guess it could be half that distance - just have a play around with the figure).

Distance returns the absolute value so it's direction independent.
B
21
S
9
G
4
Posts: 473
Reputation: 4,285

Post » Tue Apr 18, 2017 11:24 pm

Maukka, I tried the methods used on your capx by literally copy and pasting and adjusting to the objects in my project, but they are not working. It may be because I am making a platformer while your example uses the eight directional movement. I tried a couple ways to do it on my own, but they aren't as seamless as I'd like. As for the other user above me, I couldn't interpret the first line of "code", so I haven't tried it yet.
B
8
S
1
Posts: 20
Reputation: 440

Post » Tue Apr 18, 2017 11:41 pm

bump
B
8
S
1
Posts: 20
Reputation: 440

Post » Tue Apr 18, 2017 11:57 pm

fixed my problem.
B
8
S
1
Posts: 20
Reputation: 440

Post » Wed Apr 19, 2017 9:41 am

@sbz For future reference, seeing as you've already found a solution :)

The first line would be using the System|Compare two values condition, and you'd fill the fields in as follows:

First value: distance(player.X,player.Y,object.X,object.Y)
Comparison: less than
Second value: 4 (for example)

Hope that makes more sense.
B
21
S
9
G
4
Posts: 473
Reputation: 4,285


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests