Immediately determine nearest tile in travel direction

hankster112

  • Posts: 6
If I'm creating an actor that has instant movement from one point to another (in this context, a projectile that has instant contact from firing to wherever it's being aimed at), how would I determine which tile/actor is in its travel path? My idea was to draw a straight line from the origin of the actor until it makes contact with something, then use the coordinates from where it made contact, but I have been unable to figure out the best method for doing it, and it also seems like there would be an easier way to do so.

Luyren

  • *
  • Posts: 2506
In this pack (including the free demo) there is a Raycast behavior, which detects all the tiles between two points, so that could give you some ideas: https://luyren.itch.io/luyren-ai-and-combat-pack

You'd need to get the XY speeds of your projectile and plot its trajectory over time, the atan2 block could be used for that. You'd loop a number of times equal the range you want to check, and interrupt the loop if it detects any tile at the specified coordinates.

Detecting actors is a bit trickier, as there are no blocks to get actor at coordinates. There might be a code that returns if an object exists at a given coordinate or note, but I don't know what that would be. You could create a system in which each actor that is relevant sends its position to a scene behavior, and you can then query that behavior to see if any actor is within the path you ploted by using a custom block, and go from there.

Edit: alternatively, fire one actor at a very fast speed with continuous collision enabled. If it hits something, it sends back the information to the actor that fired it, and you use that to draw your projectile.



« Last Edit: January 01, 2021, 01:04:57 pm by Luyren »
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

hankster112

  • Posts: 6
Firing an actor at a fast speed doesn't get the results I need. Setting it to 500 is not instantaneous travel and causes a noticeable delay. Setting it to 999 causes it to travel faster than the game updates and only gets detected as colliding with a tile/actor either when its past it already or five tiles deep.

Max Marin

  • Posts: 38
You can do that wit da physics extension an its free
It's complicated but it's great
http://stencyl.com/developers/market