# Enemy move speed with line of sight and letterbox scale

Get help using Construct 2

### » Fri Jul 31, 2015 3:10 pm

Hey all! I'm trying to make an enemy move to a player using line of sight. The problem I have is the enemy speed is different on different screen resolutions.

I'm using Move At Angle when the enemy has LOS to the player, it uses pixels to set the speed. I tried doing something like (WindowWidth / WindowHeight) * 5 to change the speed based on the resolution but that didn't help (pretty sure my equation is flawed for this purpose but I'm a doof and can't think of a proper one). The player uses simple 8-direction WASD movement.

I'm using letterbox scaling to fit the screen. The game itself is a rogue-like that auto generates the map and letterbox scaling is the only option because of how the code works so changing it isn't much of an option at this point. Plus I really want the game to work on any resolution.

I tried enemy movement with pathfinding too but it doesn't quite work. The enemy will go to the end of the path, even if it has lost LOS to the player. This creates a situation where the enemy is chasing the player much more than expected because the enemy is walking back into the LOS by itself if the player has stopped moving.

I put together a stripped down capx that illustrates all this, sans auto map generation

Code: Select all
`http://wikisend.com/download/315374/los-example.capx`

How can I make the enemy speed constant across any screen resolution but stop him if he loses line of sight of the player? Any help is greatly appreciated!!
B
2
Posts: 4
Reputation: 152

### » Mon Aug 10, 2015 7:59 pm

Screen resolution independence requires you to use ViewportTop("layerName"), bottom, left, right... to find the relative screen coordinates and calculate all movements as a % of the screen sizes.

Frame rate independence might help too:
https://www.scirra.com/tutorials/67/del ... dependence

You could even use something like:

Every tick :: Set position: lerp(ViewportLeft("layerName"), ViewportRight("layerName"), position) :: Set position to position + 0.1*dt

to achieve both screen resolution and framerate independence simultaneously. Where position is a % of the way from the left side of the screen to the right side of the screen (i.e. varies between 0.0 and 1.0).
https://www.scirra.com/blog/ashley/17/u ... delta-time
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,867