Enemy move speed with line of sight and letterbox scale

0 favourites
  • 2 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • 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

    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!!
  • Try Construct 3

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

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

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