Pathfinding across map Unity C# - c#

I don't know exactly how to explain this, but, I'm attempting to make a game where a user controls a nation.
The game basically consists of a map, which consists of nations, which all control different provinces, which are defined in a bmp file where each is represented by a different color,
I could not send the whole thing as it was too big.
One of the primary game functions is soldiers, which can be moved across these provinces and used to occupy enemy territory or preform other similar tasks. For these soldiers to be able to move across this map, I need them to be able to find a path to the target province. I have not experimented much with path finding before, but from what I understand a path finding algorithm like A* or Dijkstra’s Algorithm would be what I need to use, and that these algorithms require nodes, representing the locations, and connections to function.
The nodes would then, in this case, have to be somewhere in the province near the center, and as I found this to be rather too complicated to produce using C#, I made another map
where the nodes are represented by black pixels, and I plan on creating a script that checks which pixels are black and set these to nodes.
From here, the only thing left for me would be connections.
I now require a way to determine connections, and I honestly have how I would do this. I would greatly appreciate if anyone could present to me a solution, and thank you in advance!

what you can try to do is Unity's in build Nav Mesh system. It is very easy to use.
Essentially, you create a pathing system - roads, rivers etc. Then you can bake the area for path finding. Essentially how it works is you will have a agent and you can set a location he has to go to. It will then find a path with the baked area.
Simply what you do then is use right-click to set the location. This can be done with a raycast. Goodluck, hope this helps.

Related

Placing objects at set locations in a pre-scanned room

Objective:
I have a pre-scanned spatial map of a room. (Carried out through an onboarding process.)
We take that map and add holographic locations/markers/digital twins to it in Unity, at pre-defined static locations. E.g wallspace, fittings, etc.
The app is then launched and contains all the holographic data in the correct location, irrespective of the users physical start location.
In short, I want an app to start, with pre-defined holograms at set locations in the real world, irrespective of where the app is started within that room.
I have read lots of tutorials and walkthroughs etc on Spatial Mapping, Spatial Understanding etc. but they do not seem to solve my problem.
I have already downloaded the 3D spatial map of the room using the hololens web browser interface, and placed holograms using Unity, with their respective scripts etc.
Now, when I start the app, all of the holograms are created correct relative to eachother, but they are only in the right place if I start the app stood at a set point, looking in a set direction.
The main idea has been to find the spatial anchors for the room, (I don't know where I get these from in the created spatial map!) and then once they are found, rotate/translate the holographic world to match the live scanned spatial anchors.
Other methods include:
- placing all the objects manually in some config first-run of the app
- creating qr codes and placing them in set locations to act in the same way as the spatial anchors in the main idea above.
Has anyone done this, and is there a better way of spawning pre-defined holograms at real-world locations every app run?
Other questions looking for similar answers, but not solving my use-case:
https://forums.hololens.com/discussion/2938/position-independent-object-placement
https://forum.unity.com/threads/how-do-i-refer-to-a-specific-space-in-a-spatial-mapped-room.425525/
You will need to setup World anchors to let Hololens remember the position of holograms in your scanned space. (More info)
I tried it and this works pretty well.
placing all the objects manually in some config first-run of the app
This is the easiest course of action you could take. Basically I would add a TapToPlace script to all of your Holograms that you want to anchor. When you first launch the app they will be in whatever place you have them in Unity. However, once you close the application and open it back up it will be in the same spot in which you put them. If you don't want the user to be able to move them so easily I would add some type of method that disables the TapToPlace with a button click or speech command.
You can find the TapToPlace script in the MRTK. This is a very easy way because you don't have to learn about Attaching and Removing World Anchors because it is done for you already.

Generating navmesh (3D) from walkable points

Here's the deal - I'm working on an algorithm/library that is able to generate a navigation mesh in virtually any environment where I can get coordinates for the controlled agent and/or for other agents within the same static environment. The only input I have, is a collection of points where an agent has been to.
(See the image here to hopefully understand what I mean)
I already got to the point where I can create navmeshes manually and navigate on them well enough. However, in larger environments, having only coordinates of, say, the controlled agent, it's really tedious and time-consuming to manually do it.
The uses for such algorithm/library for me are obvious, but I have put a lot of thought into it already, so I'll list a couple of things I'd like to accomplish:
Robotics (scans environment, only gets distance from self to a point, hence getting coordinates - no need for complicated image/video processing)
AI that is able to navigate an unknown and unseen maze (any shape or size) by exploring it
Recording walked areas and creating AI for games that don't know certain places unless they've been there
Now you hopefully see what kind of solutions I'm looking for.
I have tried a couple of things, but couldn't figure them out. One of the most successful things I've tried is giving a range to each individual point (creating a circle), and then looking for places with overlapping circles - you can most likely move on those areas. The problems with this approach started with triangulation of the areas. The resulting mesh may be a little inaccurate, but it must be able to connect to existing ("discovered") parts of the mesh seamlessly (not everything has to be interconnected somehow, as agents can disappear and reappear, but within reasonable proximity, connect the mesh).
Some more information: I'm working in C#, though solutions in java, C++/C, objective C, pseudocode etc are equally acceptable.
P.S. I'm not interested at all in answers like "just use this library" or "use this other language/environment" etc... I want an algorithm. Thank you in advance.
I can help with 2D path finding. You need to find the red outline. Then you can use a voronoi diagram with the red outline (not the agents points). Remove all edges outside the red outline and the remaining edges can be used to navigate the shape by someone/something. Read about it:http://www.cs.columbia.edu/~pblaer/projects/path_planner/.

How to Combine Vertices and edges into one In Unity

I'm new to Unity and I'm making a car racing Game. Now, I'm stuck at some point. I was looking for some solution of my problem, but couldn't succeed.
My problem is:
When I run my game on my phone, it sticks badly because whenever there are several buildings in front of the car camera, like one building behind another building, it lags. Reason for this is there are so many vertices and edges at that time, So the Car Camera is unable to capture all that stuff at same time.
How do I preload the 2nd Scene while loading 1st Scene?
I am using Unity free version.
In graphics programming, there is a common routine to simply don't draw objects that aren't in the field of view. I'm sure Unity can handle this. Check link: Unity description on this topic
I'm not hugely knowledgeable about Unity, but as a 3D modeller there's a bunch of things you can do to improve performance:
Create a simplified version of your buildings with fewer polygons for use when buildings are a long way away. A skyscraper, for example, can be as simple as a textured box.
If you've done that already, reduce the distance at which the simpler imposters are substituted for the complex versions.
Reduce the number of polygons by other means. A good example is if you've got a window ledge sticking out of the side of a building, don't try and make it an extension of the body. Instead, make it a separate box, delete the facet that won't be seen, and move it to intersect with the rest of the building.
Another good trick is to use bump maps or normal maps to approximate smaller features, rather than trying to model everything.
Opaqueness. Try not to have transparent windows in your buildings. It's computationally cheaper to make them just reflect the skybox or a suitably blurred reflection imposter. Also make sure that the material's shader is in Opaque mode, if it supports this.
You might also benefit a little from checking the 'Static' box on the game object, assuming that buildings aren't able to be moved (i.e. by smashing through them in a bulldozer).
Collision detection can also be a big drain. Be sure to use the simplest possible detection mesh you can - either a box, cylinder, sphere or a combination.

How to visualize nodes(agents) of Neural Network algorithms in a form in c#

These days I am trying to develop two algorithms in c#. Self Organizing Map, Particle Swarm Optimization and Glowworm Swarm optimization. I know how the algorithms work but there is an issue which I am not sure where to start from.
Agents in the search space which try to find the best solution have some coordinates(x and y). I don't know how am I should represent the position of agents visually in a form in each iteration. One option may be using charts in c# and represent point so that in each iteration I am going to change the position of the agent(point) in the chart. Another way may be using drawing classes in c# and drawing circles or points in a panel based on the x and y coordinates. Which classes of .net should I use to represents points in a search space visually(in a 2D space).
I hope you understood me and thank you for reading this post.
If your design variables are N-dimensional, N>3, it is not an easy job to visualize the entire domain of interest. You can either project the N-Dim to 2D or 3D to get a "section" of the fields.

Shopping Mall Map Directory Editing [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a shopping mall directory image (for example like this: http://www.westfield.com/annapolis/map/ ) and want to make an application like this http://www.youtube.com/watch?v=LNj8D8JKv-4&feature=related where I can draw the path between two locations without needing make many images for the paths.
So, What techniques (Library, programming techniques, softwares .. etc) do you suggest to do this using .NET (Windows Forms/ WPF) application?
EDIT for BOUNTY
I am looking for some start like. I am on 3rd Floor. I have a image of third floor. There is a point of entrance from 3rd floor in map. There are 29 seats in the floor. I want to show with line path, where is somebody's seat. I want to do it through Web App. C# MVC 4.5 Where should I start from ? Any sample code will be very helpful.
I solved similar problem some time ago. In short, I was making a game like Heroes of Might and Magic and since I didn't want to draw background myself I decided to use a static image which I would simply manipulate along with player moves.
So we found an open-source game with a map editor that we used for creating of a map background. Then we created a mapper that would load an image created from the map editor and user would mark places on a grid. The following image is a screenshot from our map mapper.
There was the image, and drawed grid with adjustable size for cells so that we could map objects very precisely. The yellow boxes with an item inside are mapped objects (some of them actually do not give a sense, it is just a proof of concept). When we were content of the result, we would safe position and information about all obejcts to a xml file so that I can be used from our game application.
In our game we have defined a class called TileMap that was aware of all objects (stored as instances of a class Tile) on the map and all players move requests were permitted or forbidden by it.
Finally, this is how I would solve your problem. I have only positive experience with this solution. Create an application that would allow to you to specify where there is a path, where there is a store and how it is called, and so forth. Serialize values to xml or another format you are confident with. Then, create an application that works with these obejcts, define a tile map and you are nearly finished. Now you just need to implement path finding and drawing. Path finding is easy, there are plenty different algorithms with different efficiency and speed. Once you know what tiles you have to cross in order to get into a destination, simply draw stars, arrows or whatever you like above the tiles.
Cons
you need to create two applications
Pros
no need to generate more images, you are drawing on a transparent layer and you can safe already generated paths in memory or file
quite easy implementation, just a lot of code
feel free to choose a technology - we used WinRT, but WPF and even WinForms are also suitable
if you like GUI applications, you will have a plenty of fun while doing this :)
Feel free to ask any design and even implementation details questions .
Prepare the list of all places that you want to be searchable. Give each one an ID. The stairs and elevators should have IDs too.
Create the map floor masks. The easy way is the "coloring book" technique. Create semi-transparent layer in Photoshop and overlay it above the map. Then, draw the walls with some set "color 1". Then, draw each distinct place with a distinct color. Just convert the place ID to Hex and use that hex value as the color. Draw the mask for each floor (in a separate image).
Create the map loader. It should load the mask images and extract the object position and passing ability information. You have to find the position (x, y, floor) of each place by scanning the maps and looking at the pixel color hex value. You have to locate the stairs and elevators, their positions and the floors that they connect.
Implement the pathfinding algorithm like A*. It's quite easy and looks like viscous water flowing to the destination's low point. For each position (x, y, floor) one can move in any of the four directions where there aren't walls. And if there is an elevator at that point, one can move to some other floor. The algorithm can quickly find the best route between any two (x, y, floor) points.
When user gives you the name of the place where he wants to go, you need to find out the user's position coordinates (you may try to use GPS) and the destination position (use the object location table, you prepared when you loaded the map on step 3). Give these two (x, y, floor) points to the pathfinding algorithm to get back the route - the sequence of the (x, y, floor) points leading to the destination.
Analyze the route. You need to scan the route and find out what floors does it pass through. Split the route in chunks where each chunk belongs to a single floor. Now you have a list of floors and the route points for each of the floors.
Visualize the floors and their route parts by drawing the route points over the floor maps. To increase the root point spacing, you may just draw every 10th point or so. With HTML5, the sequence of route points can be drawn as an SVG or canvas overlay on top of the floor map image background.
The best way to set up something like this is to pick up a book on game programming, as it will give you a lot of information on setting up paths around "solid objects". The actual UI technology should not matter as much, so choose WPF or Windows Forms, HTML5 etc. Of the choices you have, I would probably aim for WPF or Silverlight, as it gives you much more flexibility on creating the UI. But I would not be adverse to HTML5 either.
You can definately do the whole thing in WPF, you're looking at drawing simple paths so you need to chunk your project into multiple sub issues:
1) How to draw the UI area (i assume you already know that)
2) How to draw the map, it heavily depends on the map data you have but it could be as simple as a single image, please add more detail for your source
3) How to figure out the path, for this you will need to use some form of pathfinding algorithm (one of the simplest one is A*, but there is a myriad of algorithms for different needs)
4) How to draw the Path, this depends on what you're looking for once again
I know it isn't much of an answer yet but depending on your needs (please add a comment bellow) i'll edit it to help you the best i can.
It would be pretty significant undertaking if you are trying to do this whole thing by yourself. All you have is image of shopping mall. From there you need to convert it in to vector data which in itself a fairly significant project. Then you will need to design navigation algorithms and then you need to setup UX for the whole thing. IMO, all these would require a lot of resources and research if you want to do this nicely and accurately.
Fortunately here is a good news: Google has been trying to do same thing for quite sometime and throwing lot more resources than that are likely at your disposal. Their effort is called "indoor mapping" which you can pretty much leverage out-of-box for your scenario. I'm going to give out here pointers to start you off as you have asked.
First visit Google blog to get familiarize with their indoor maps initiative. Then try out adding your floor plan in Google maps here. You are basically uploading image and aligning with the building in Google maps at this point. Here's another tutorial. Note that this does not make your floor plan navigable and may not show yet users location on it because to do that you need data from wifi/cell towers to triangulate users location on floor plan. We'll go over that next. If you have tons of these floor plans, I'd suggest taking help of mechanical turk or such service to have other humans do it for you cheaply. Google maps allows you to keep floor plan privates by using overlays but likely you don't want to do that so users can access it from anywhere.
Next, you want to make your user locatable on your floor plan. This involves getting data such as wifi/cell tower signals at different points on your floor plan. Google has app for this. And here's little demo. You can also use SketchUp to add vector data and polygons.
Next, you want to embed Google maps in your app so it becomes integral part of your app instead of users having to go through Google Maps website. To do this look at Maps SDK (here's link for iOS, and snippet for indoor maps).
Good luck!
You may easier this job by looking into Google map indoor solution. http://maps.google.com/help/maps/indoormaps/
No programming except a web page is needed.

Categories

Resources