Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: 2D sub-Tile Line intersection
    text
    copied!<p>I have some problems getting an algorithm for my game to work and hope someone here can help me. Google didn't seem to be a good help as most solutions just work for full tiles.</p> <p>In the game units can occupy different positions inside a tile, i.e. they can be in the upper left corner, center, bottom right, ... position of tile (2/3), i.e. (2.2/3.1), (2.5/3.5), (2.8/3.9).</p> <p>If they move from position (2.2/3.1) to (5.7/4.1) i require a check to see if there is an obstacle in the path.</p> <p>My current algorithm is:</p> <ol> <li>Starting from (2.2/3.1)</li> <li>Calculate the angle of the movement (i.e. 70 degree)</li> <li>Move 0.1 steps in that direction</li> <li>Check which tile i'm on (floor(p.X)/floor(p.Y))</li> <li>Repeat from 2</li> </ol> <p>This algorithm works but to me it doesn't look very efficient as an obstacle can be only a full tile, not a part of a tile (units don't collide). If i increase the step size i begin to miss tiles that are only crossed slightly (i.e. you only cross the lowest left corner). Even with a step size of 0.1 it's still possible to miss an obstacle.</p> <p>I tried to find a solution to take the sub map (all tiles with the corners (floor(start.X)/floor(start.Y)) and (ceil(start.X)/ceil(start.Y)), move through every tile and check mathmatically if it gets crossed. Sadly i seem to lack the required math knowledge for this check.</p> <p>My last idea was to take all 4 borders of a tile as a line and do line-intersection but that seems to be slower than my original approach.</p> <p>Any hints?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload