I want the enemy to only move towards the if there is no wall between the enemy and the player. I tried to use the lines from this but it was super laggy.

1 Comment


If I understand what you want to do, you don't need to draw lines. You just want to know if there are any objects between the enemy and the player.

There are no ray casts as such in Wade, but you can check if there are any objects in an area. You can make the area 1 pixel tall, so it becomes effectively a line.

You are correct, one way of doing it is using the code snippet in the post you linked to. However in that case, don't add the scene object to the scene. In fact, don't even make a scene object. Just make a sprite, and check what it overlaps using Sprite.getOverlappingObjects. From the documentation:

Sprite.getOverlappingObjects(searchAllLayers, precision)
Get an array of objects overlapping this sprite

boolean searchAllLayers (optional): Whether to extend the search to all layers. This is false by default, meaning that only overlapping sprites on the same layer will be considered.

string precision (optional): How accurately to search for overlaps. This can be 'axis-aligned' (which would consider the axis-aligned bounding box of the sprites); 'oriented', which takes into account the rotation of each sprite; or 'pixel' that does a (much slower) per-pixel test, discarding transparent pixels. Default is 'axis-aligned'

Returns Array : All the objects that are overlapping this sprite


What you chose for those parameters can have a big effect on performance.


Alternatively, without creating any sprites, you can use wade.getObjectsInArea(). This is much faster, howerver it is limited to axis-aligned tests (i.e. it does not take into account any rotation), so it only really works well if the player and the enemy have similar x OR y coordinates.



Post a reply
Add Attachment
Submit Reply
Login to Reply