How do I keep a top-down sprite on a platform?

0 favourites
  • 6 posts
From the Asset Store
Set of tiles to create a map for top-down games with island theme
  • What I want to do is have a player sprite be able to freely move around specifically on this platform in a top-down game. However, it would have no way of escaping the platform or moving off of it.

    What I have so far is code that enables the sprite to be controlled via the 8-direction arrow keys as long as its on the platform. If it tries to move off, some other code is supposed to reverse its movement the moment the sprite isn't colliding with the platform.

    However, I came across the problem of the sprite still slowly moving off of the platform anyway.

    Can anyone give me some pointers?

  • Are you using physics? Sometimes if you mix physics with other behaviors things take on a life of their own. You'd need to turn physics off when using 8-Direction.

    If that isn't it, you may need to post an example.

  • How about using invisible blocks with the solid behaviour?

    You'll just need to line them up where you dont want your player to be able to walk.

  • What I want to do is not let my character move off the platform using the 8-key directions, but instead move off when the mouse is clicked on another platform. Would the solid blocks allow that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There isn't a way to disable the solid behavior, but you can move the walls out of the way for those times when you don't want them there.

    Create two instance variables like startX, startY in the wall object. Then at start of layout set wall's startX=self.x and startY=self.y.

    Then when the player clicks on the other platform, set the position of the walls to something off the layout like

    walls->set position(-500,-500)

    When the player has moved to the next platform, put the walls back in place:

    wall->set postion(self.startX,self.startY)

    You need to take care that the player doesn't get stuck in the middle of a wall when you put them back.

    You also can just move the walls that the player collides with, but it is a bit more difficult to know when to put the walls back.

  • The problem described in this thread isn't exactly what you were talking about, but my example shows how to trigger the move of the solid object and move it back the way I described above.

    Bounce and Jumpthru

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