I am looking for nice way to create path from player to desired point in 2d sidescrolling platformer style. I am struggling to find a solid solution to achieve this:
So I want to click somewhere on 2D plane and generate path from player to that point. Few options I’ve thought of:
Raytracing from from player to click point, and tracing the path that way. This would be quite inefficient I believe as I’d need to find angles of every surface that raytrace collides with (is there even easy way to do this?) and this could lead to many traces.
Some sort of builtin pathfinding. I’d propably want to include options like climbing on roofs and vertical surfaces, so using a premade pathfinding algorithm seems like an option that would require a bit of tweaking.
Pre-generating paths. This way I’d have paths generated all over the collision objects at start of the game and hiding them. Perhaps some sort of object that ‘runs’ through the whole level and generates the paths along the way.
I am asking this as I believe there is probably something I have not thought of that is a much better solution than any I’ve mentioned above!
Mm.
Does it ver change angle, or is it always a straight line?
Regardless, I would click point to move to. Mark this position in world, or screen space. Get the position of the player, in world or screen space (player pos and click pos must both be in the same type of space… I would go with world).
Then, now, you have two vectors, positions is space that dictate the beginning and end of the line. Now, you can mark that line with sprites, little dots.
I haven’t thought about is much, but I think I would use this…Unity - Scripting API: Ray.GetPoint, I would cast a ray from player to click point (make sure the z axis of click point (world space) is the same as z for the player. Now, place a dot every few units along get ray point until the end.