How do I (In Description)

  • 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

  • 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.

  • 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.

  • 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?

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • bump

  • fixed my problem.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)