Position player based on movement direction in top down game

0 favourites
  • 4 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • In my top down game I want to position the player closer to the edge of the window depending on the direction they are facing, so that more of the layout in front of the player is visible compared to when the player is positioned in the centre of the window.

    If my player sprite is moving up it should be positioned at the bottom of the window, if the player sprite is moving left it should be positioned at the right of the window.

    I've tried setting an invisible camera sprite in front of the player and setting the scroll to behavior to this camera, with a different offset depending on the direction the player is moving but this doesn't seem to work.

  • The approach below works well when the player is only moving in one direction but in a top down game where the player moves in 4 directions I have to change the camera position based on the angle of the player, and the change in angle results in a sudden and jarring shift in camera position:

    Player is between 135 and 225 degrees

    set position to (lerp(Camera.X, Player.X - 1000, 0.05), lerp(Camera.Y, Player.X, 0.05))

    Player is between -45 and 45degrees

    set position to (lerp(Camera.X, Player.X + 1000, 0.05), lerp(Camera.Y, Player.Y, 0.05))

    Player is between 225 and 315 degrees

    set position to (lerp(Camera.X, Player.X, 0.05), lerp(Camera.Y, Player.Y - 1000, 0.05))

    Player is between 45 and 135 degrees

    set position to (lerp(Camera.X, Player.X, 0.05), lerp(Camera.Y, Player.Y + 1000, 0.05))

    I'd like to smoothly move the camera in a circular motion as the player changes direction. Any suggestions appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • quick idea ...

    https://db.tt/LNQqAs76

    beta r211

    A bit of a cheat - but it (almost) works <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Thanks, an interesting solution. It works well but on second thought the rotation can be disorienting if the player is constantly changing direction. In the end I opted for a simpler approach for the camera.

    Every Tick >>

    Set position to (Player.X, Player.Y)

    Move 1000 pixels at Player.Angle

    This positions the camera as required and minimises camera rotation when the player is changing direction.

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