Restrict Navigation2D to the 4 cardinal points - game-development

I have this procedurally generated maze which I solve using the Navigation2D. It looks like this
I have turned Show Navigation on in the Debug menu hence the green outline. As the sprite takes a corner you can see it's taking the slanted line.
I want it to restrict itself to right-angled turns only. I configured the navigation polygon to 4 pixels wide, and the inverse of that polygon as my collision polygon so it's supposed to be a tight fit?. I am confused as to why there's that blurry outline at the vertices.
My repo is here https://github.com/plasticruler/tower-defence-maze
Also, any comments on why it doesn't always return the shortest path?

I've done some research and even tried to code it myself but sadly no positive results. You could try solving the maze by sending some "agents" with restricted 4 directional movements and the agent with the shortest path is your answer something like an Ant simulation Video I recommend watching about Ant simulation.
I also had found this useful video by GDquest that you might find helpfulVideo

Related

GODOT: What is an efficient calculation for the AABB of a simple 3D model from a camera's view

I am attempting to come up with a quick and efficient means of translating a 3d mesh into a projected AABB. In the end, I would like to accomplish something similar to figure 1 wherein only the area of the screen covered by the cube is located inside the bounding box highlighted in red. ((if it is at all possible, getting the area as small as possible, highlighted in blue, would increase efficiency down the road.))
Figure 1. https://i.imgur.com/pd0E20C.png
Currently, I have tried:
Calculating the point position on the screen using camera.unproject_position(). this failed largely due to my inability to wrap my head around the pixel positions trending towards infinity. I understand it has something to do with Tan, but frankly, it is too late for my brain to function anymore.
Getting the area of collision between the view frustum and the AABB of the mesh instance. This method seems convoluted, and to get it in a usable format I would need to project the result into 2d coordinates again.
Using the MeshInstance VisualInstance to create a texture wherein a pixel is white if it contains the mesh instance, and black otherwise. Visual instances in general just baffle me, and I did not think it would be efficient to have another viewport just to output this texture.
What I am looking for:
An output that can be passed to a shader informing where to complete certain calculations. Right now this is set up to use a bounding box, but it could easily be rewritten to also use a texture. It also could be rewritten to use polygons, but I am trying to keep calculations to a minimum in the shader.
Certain solutions I have tried before have worked, slightly, but this must be robust. The camera interfacing with the 3d object will be able to move completely around and through it, meaning at times the view will be completely surrounded by the 3d model with points both in front, and behind.
Thank you for any help you can provide.
I will try my best to update this post with information if needed.

draw outline for some connected lines

I have some lines that are connected at various points. I want to draw the outline of these lines and I also want to deal with the extra lines at the connection points.
I have seen two similar questions in this website: Here and here
I have handled the normal cases by offsetting the Centerlines and then changing the start and end points of the lines.
but I haven't been able to deal with special cases when the points are near each other.
Unfortunately, my reputation is low I couldn't post images to explain this better.
I'm coding in Visual Basic .net and I'm writing for Autocad, but any advice will be very useful to me.
most problem cases are solved by translation vectors intersection check
black is the original line/curve whatever ...
gray is translation vector (normal to black and size = outline distance)
blue is outline
if the translation vectors not intersect then it is most likely all OK but if they do then just do something like this:
cut off these points from outline
or create some singular point from these intersections
it is more tricky but can avoid some problem cases from bullet #1
Also sometimes help if there is bigger density of control points
Hope it helps a little...

Detect multiple bodies in Kinect?

I am working with kinect in openframework using the ofxKinect addon, which is great and plenty fun!
Anyway I am looking for some pointers or a direction when dealing with multiple bodies on the screen. I was thinking of making a rect around each detected body and when the rects intersect something could happen, an effect or anything.
So what I am looking for are ideas or something that could point me to the right direction of detecting multiple bodies when using a kinect.
Right now based on the depth image I get from the kinect I go through each pixel and create a bunch of smaller rectangles with a padding and group them in a larger rectangle bound if they are separate from another rectangle group. This is not ideal as it only deals with the pixel values and is not really seperating bodies from eachother and is not giving me the results I am looking for.
So any ideas would be greatly appreciated!
If you want to use ofxKinect a quick solution would be to threshold on depth and assume bodies and no other objects will be within a depth range. This should make it easy to use the OpenCV's contour finder to isolate the outlines of the bodies and get the bounding rectangles. If the rectangles intersect(and ofRectangle already does the math you), trigger the reaction you need. Also don't forget to do that once if the effect isn't showing already, otherwise you will trigger the effect multiple times per second while the two bodies' bounding rectangles intersect.
You could try something a bit more hardcore and using ofxCv(not just ofxOpenCV) to tap into the HoG functionality. This is slow in itself and not ideal with the depth map, but hopefully you can run in every few seconds just to detect a person and the depth, then keep tracking that movement.
Personally, if you want to track people with the Kinect I recommend using ofxOpenNI as if already provides the scene segmentation feature and even if you don't track the skeletons you can still get useful information like the pixels pertaining to each body and they're centre of mass. I'm guessing Microsoft KinectSDK has a similar feature and there should be an oF addon, but it's windows only.
ofxKinect/libfreenect does not offer any people detection features, so you will need to roll your own.

UIBezierPath subtraction from another UIBezierPath

I am making an app that allows the user to draw on the screen with his finger in different colors. The drawings are drawn with UIBezierPaths but I need an eraser. I did have an eraser that was just a path with the background image as the color but this method causes memory issues. I would like to delete the points from any path that is drawn on when eraser is selected.
Unfortunately UIBezierPath doesn't have a subtraction function so I want to make my own. So if eraser is selected, it will look at all the points that should be erased and see if any of the existing paths contain those points, then subdivide the path leaving a blank spot. But it should be able to see how many points in a row to delete not do it one at a time. In theory it makes sense but I'm having trouble getting started on the implementation.
Anyone have any guidance to set me on the right 'path'?
Upon first glance, it appears that you could do hit detection on a UIBezierPath by simply using containsPoint:. That works fine if you want to determine whether the point is contained in the fill of a UIBezierPath, but it does not work for determining whether only the stroke of the UIBezierPath intersects the point. Detecting whether or not a given point is in the stroke of a UIBezierPath can be done as described in the "Doing Hit-Detection on a Path" section at the bottom of this page. Actually, the code sample they give could be used either way. The basic idea is that you have to use the Core Graphics method CGContextPathContainsPoint.
Depending on how large the eraser brush is, you will probably want to check several different points on the edge of the brush circle to see if they intersect the curve, and you'll probably have to iterate through your UIBezierPaths until you get a hit. You should be able to optimize the search by using the bounds of the UIBezierPath.
After you detect that a point intersects a UIBezierPath, you must do the actual split of the path. There appears to be a good outline of the algorithm in this post. The main idea there is to use De Casteljau's algorithm to perform the subdivision of the curve. There are various implementations of the algorithm that you should be able to find with a quick search, including some in C++.

top down game - checking, drawing enemy's line of sight area with obstacles

Examples of what i'm going to need:
I'm using cocos2d to draw a CCTMXTiledMap, on those tiles i'll have to draw the LOS triangle.
How would i test if the player is within that triangle, taking obstacles into account?
How would i draw the line of sight area like in the examples above?
BTW, i wasn't sure if this should have been posted here or on gamedev, don't be mad.
You may wish to look at point-in-polygon algorithms such as the ray casting algorithm described here.
You can break up the triangle to account for obstacles, or just make a more complex polygon. You should be able to find an implementation to suit your needs online.
You may also want to take a look at this article for some inspiration. You can maintain a tree like structure, a root triangle (or fulcrum) that can be used to determine whether a point is in general line of sight, with the children (triangles) taking obstacles into account. That way you can quickly eliminate more complex checks.
In the image below the dark blue dots are quickly eliminated from further checking as they do not fall within the root viewing triangle.