How do I adapt AStar in Godot to platformers? - path-finding

I've been looking for a robust method of pathfinding for a platformer based game I'm developing and A* looks like it's the best method available. I noticed there is a demo for the AStar implementation in Godot. However, it is written for a grid/tile based game and I'm having trouble adapting that to a platformer where the Y axis is limited by gravity.
I found a really good answer that describes how A* can be applied to platformers in Unity. My question is... Is it possible to use AStar in Godot to achieve the same thing described in the above answer? Is it possible this could be done better without using the built in AStar framework? What is a really simple example of how it would work (with or without AStar) in GDscript?
Though I have already posted a 100 point bounty (and it has expired), I would still be willing to post another 100 point bounty and award it, pending an answer to this question.

you could repurpose the Navigation2D node for platformer purposes. The picture below shows an example usage. The Navigation2D node makes it possible to navigate the shortest path between two point that lie within the combined navigation polygon (this is the union of all NavigationPolygonInstances).
You can use the get_simple_path method to get a vector2 array that describes the points your agent/character should try to reach (or get close to, by using some predefined margin) in sequence. Place each point in a queue, and move the character towards the different points by moving it horizontally. Whenever your agent's next point in the queue is too high up to reach, then you can make the agent jump.
I hope this makes sense!
The grey/dark-blue rectangles are platforms with collision whereas the green shapes are NavigationPolygonInstance nodes
This approach is by no means perfect. If you were to implement slopes into your game then the agent may jump up the slope instead of ascending it normally. It is also pretty tedious to create all the shapes needed.
A more robust solution would be to have a custom graph system that you could place in the scene and position its vertices. This opens up the possibility to make one-way paths and have certain edges/connections between vertices marked as "jumpable" only. This is a lot more work though if you can not find any such solution online.

Related

How to generate recursive shapes like geokone.net using GL.Begin?

http://app.geokone.net/ is an open source javascript app for generating shapes (if you can look at it, it's really fast, for 5 seconds, I'm sure you'll get the idea).
It's hard for me to go through it because it's a lot of code, what is the general idea?
also, I need those shapes as GameObject with polygon collider around them (anything from 0 to 20 of them on the screen at the same time, could be different shapes also), is it even possible with GL?
would GL help me? I think GL would be fast for just 1 shape or something (as it's using recursion), but for what I want, I think drawing them in real time to a texture, then using the texture as a sprite would be faster (as I can save the sprite for shapes that are the same), or maybe I should use a shader? any other method that you can think of?
and for the algorithm itself, what is the general idea?
You don't want to use GL, look into custom mesh generation with MeshFilter. It is required for the colliders anyway.
Meshes have to be updated just once and probably will be faster than any optimisation you proposed. You might need a shader to draw it, though.
As for the algorithm, I'm afraid you have to look into it yourself or hire someone for it. StackOverflow is for helping with issues, not doing the work for you. If you need a hint, look into basic fractals

Box2D collision manifold?

I have seen around that there is a b2Manifold. What I want to accomplish is to detect whether or not a collision was on the top part or not of one of the objects that were colliding.
I have already set up a b2ContactListener and it works fine. I would just like to provide more accurate collisions by setting up the manifold to detect if one b2Body is on top of the other b2Body that it collided with.
How would I do this?
Thanks!
http://postimage.org/image/kbfr7c5db/

How to make sure a large polyline doesn't go off-road?

I have an iOS app that uploads coordinates to a server. These coordinates can then be viewed in a map, through Google Maps. This is shown as a simple polyline. However, due to the GPS not being very precise, the polyline is often off-road.
I tried using Google's direction service, but it has a limit on how many requests you can send (and there can be a few thousand points on the polyline).
I have no idea how I can solve this problem. Could anybody help me?
I suspect the only way do do this is with manual intervention. The only way I can think of doing it programmatically would involve lots of queries to the directions service (to get "snap to road" functionality), and that probably would still need someone to check that it got it right (or at least need to include some code to look for extra loops to turn around or detours on to side roads that don't make sense).
Whereas if someone gets directions from start to end then drags them to match the track it would be pretty simple to get a version of the track that follows the roads.
The paper discussed in this thread might give you some ideas

Coordinate System of Flame Fractals

I have been doing some research on flame fractals in preparation of creating my own flame fractal generator. I just have one question: What coordinate system is used in the flame fractal algorithm?
Is it like the Mandelbrot Set with complex numbers, or is it a real number system?
Additionally, what is an optimal range to graph the flame fractals within (i.e. Mandelbrot uses (x-> -2 to 2),(y-> -2i to 2i))?
Original Article about flame fractals (22Mb PDF)
The coordinate system in Apophysis, flam3, and other implementations use (x,y), or (x,y,z).
if it has 3d hack. However, some variations interpret (x,y) as if it was a complex number, for example, the mobius variation, or the julia variation.
The exact details on how the math is done is hard to understand, nobody really knows,
since the existing code is very old, and has been developed by many people.
I have, for example, experienced some problems related to the y coordinate behaving strangely.
EDIT: Ah, Apophysis and flam3 uses sort of a camera function, which has a center point, rotation, and magnification. The center point is what will be mapped to the middle of the screen, and the rest, you'll be able to figure out.
I am actually coding on a Java implementation, which can be found here: http://sourceforge.net/p/flamethyst/home/Home/
Browse the code for details on camera, coordinates, etc.
To answer your specific question, I believe that an error in the source code caused the y coordinate to flipped in one of the transforms so that the negative y axis extends upward and the positive y axis extends downward.
To answer your actual question about where to find information about the aweful mess that is the apophysis codebase, the secret place on the internet where most of the experts in how apophysis actually works is a deviantart chatroom at chat.deviantart.com/chat/aposhack. It requires that you sign up for a deviantart account. In the chat, there are several people labeled 'wizards' who either work with the source code, have gotten sick of the source code and are writing their own flame generators, or are Thomas Ludwig, creator of Chaotica, which is a fractal flame renderer that does not have many of the bugs and mathematical issues as apophysis.
If you are still working on a flame generator, I invite you to stop by and talk fractals with us.

Best way to detect collision between sprites?

Whats the best way to detect collisions in a 2d game sprites? I am currently working in allegro and G++
There are a plethora of ways to detect collision detection. The methods you use will be slightly altered if depending on if your using a 2d or 3d environment. Also remember when instituting a collision detection system, to take into account any physics you may want to implement in the game (needed for most descent 3d games) in order to enhance the reality of it.
The short version is to use bounding boxes. Or in other words, make each entity in the world a box, then check if each of the axises of the box are colliding with other entities.
With large amounts of entities to test for collisions you may want to check into an octree. You would simple divide the world into sectors, then only check for collision between objects in the same sectors.
For more resources, you can go to sourceforge and search for the Bullet dynamics engine which is an open source collision detection and physics engine, or you could check out http://www.gamedev.net which has plenty of resources on copious game development topics.
Any decent 2D graphics library will either provide its own collision detection functions for everything from aligned sprites to polygons to pixels, or have one or more good third party libraries to perform those functions. Your choice of engine/library/framework should dictate your collision detection choices, as they are likely far more optimized than what you could produce alone.
For Allegro there is Collegro. For SDL there is SDL_Collide.h or SDL-Collide. You can use I_COLLIDE with OpenGL. DarkBASIC has a built in collision system, and DarkPhysics for very accurate interactions including collisions.
Use a library, I recommend Box2D
This question is pretty general. There are many ways to go about collision detection in a 2d game. It would help to know what you are trying to do.
As a starting point though, there are pretty simple methods that allow for detection between circles, rectangles, etc. I'm not a huge fan of gamedev.net, but there are some good resources there about this type of detection. One such article is here. It covers some basic material that might help you get started.
Basic 2d games can use rectangles or circles to "enclose" an object on the screen. Detection of when rectangles overlap or when circles overlap is fairly straightfoward math. If you need something more complicated (such as convex artibrary polys), then the solution is more complicated. Again, gamedev.net might be of some help here.
But really to answer your question, we need to know what you are trying to do? What type of game? What type of objects are you trying to collide? Are you trying to collide with screen boundaries, etc.
Checking for collision between two balls in 2D is easy. You can google it but basically you check if the length of the two balls radius combined is larger or equal to the distance between the center of the two balls.
Then you can find the collision point by taking the unit vector between the center of the balls and multiply it with one of the balls radius.
Implementation of a collision detection system is a complicated matter, but you want to consider three points.
World of objects. Space Partitioning.
If you do a collision check against every 2d sprite in your world against everything else, you'll have a slow slow program! You need to prioritize. You need to partition the space. You can use an orthogonal grid system and slice your world up into a 2d grid. Or you could use a BSP tree, using lines as the seperator function.
Broad phase collision detection
This uses bounding volumes such as cylinders or elipses (whichever approximates the shape of your sprites the best) to determine whether or not objects are worth comparing in more detail. The math for this is easy. Learn your 2d matrix transformations. And for 2d intersection, you can even use high powered video cards to do a lot of the work!
Narrow phase collision detection
Now that you've determined that two or more objects are worth comparing, you step into your fine tuned section. The goal of this phase is to determine the collision result. Penetration depth, volume encompassed, etc... And this information will be fed into whatever physics engine you got planned. In 3d this is the realm of GJK distance algs and other neato algorithms that we all love so much!
You can implement all of this generically and specify the broad and narrow resolutions polymorphically, or provide a hook if you're working in a lower level language.
Collisions between what? It depends whether you use sprites, concave polygons, convex polygons, rectangles, squares, circles, points...

Resources