Position player based on movement direction in top down game

Get help using Construct 2

» Thu Aug 13, 2015 12:23 pm

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.
B
4
Posts: 7
Reputation: 214

» Sun Aug 16, 2015 5:43 pm

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.
Last edited by Capriomo on Sun Aug 16, 2015 9:54 pm, edited 1 time in total.
B
4
Posts: 7
Reputation: 214

» Sun Aug 16, 2015 8:04 pm

quick idea ...

https://db.tt/LNQqAs76

beta r211

A bit of a cheat - but it (almost) works
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

» Mon Aug 17, 2015 7:02 pm

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.
B
4
Posts: 7
Reputation: 214