In my little top-down, run-from-the-scary-ass-aliens game, programmed in C# XNA, I have some aliens and some walls (amongst other things). Something I'm having trouble figuring out is how I can steer the aliens round walls. At the moment they run into them like idiots, sliding along and MAYBE reaching their target if they poke out the other side.
Here's my professional illustration of the problem:
problem http://imageshack.com/a/img829/6545/wsf4.jpg
So directly, my questions are:
How do i check if there is a wall between alien and target?
How do i steer them around along the shortest route?
Algorithm/explanations welcome, c# a bonus! :)
Some same assumptions to hopefully make the calculation easier:
- Aliens and walls have AABB
- walls are always vertical or horizontal
and i'm hapy to provide any additional information if necessary :)
When I did my research for the wp7/wp8 game that I developed, I solved this kind of issue with A* pathfinding. (www.policyalmanac.org/games/aStarTutorial.htm).
You can also use Dijkstra's algorithm for pathfinding. http://i.stack.imgur.com/VMkdl.gif
That was my first approach. I've since learned of a different way to also approach it. This builds upon A* pathfinding and makes use of AI Steering forces/behaviors. You may even be able to solve this problem mostly with just steering forces.
Steering forces, simply, compel an entity to move based on it's goal and environment. You stack movement (velocity) forces onto an entity and the sum of those forces moves the entity in a desired way.
So an entity might have the movement desire to move towards your monster, avoid the wall, and avoid the boundaries of the map. These velocities multiplied by % value (how much you want them to apply to the global force) all added together gives you the final force.
All of these individually have problems and restrictions. I think a combination of A* and steering forces might be best for you.
Example: http://i.stack.imgur.com/u7ECs.jpg'
EDIT: Dijkstra's is more node based if you want to manually place nodes. If placing nodes is not an option, I believe steering forces are your best bet.
Related
I am trying to make a game like Color Hole. I've created a ground and a 3d cylinder. I want this cylinder act like a hole instead of a solid cylinder. Is there any opinion how can I do this without using Blender or etc?
For modeling and mesh prototyping within unity there are very cool assets, such as this, or this.
The most affordable of the solutions of course is to import the model you want as wanted from your modeling program.
It would expected to be possible with pro-builder (modeling tool integrated in unity). However its not.
Window->PackageManager->Probuilder
Then you need to enable the experimental features:
Edit->Preferences->ProBuilder
Then there is a tool that its supposed to make union, instersection and substraction of meshes:
However it does not work and at least for what I tried, I obtain this error always:
StackOverflowException: The requested operation caused a stack overflow.
UnityEngine.ProBuilder.Csg.Plane.SplitPolygon
(Unity version 2018.4.12). Maybe it can be checked if there is an issue with the unity version and if the pro-builder approach migh work in others.
If you attach a script to the "hole" object, you could detect other objects entering in OnColliderEnter(). Then, using the OnColliderStay() method, you could move them downwards "through" the hole, then destroy them (or whatever you want to happen when they pass through the hole).
It's kind of a hacky solution, but it would work if you're unable make a custom asset. It's not going to give you physics engine interaction though, so making the object tumble realistically through the hole will be more effort than it's worth.
I am new to programming, so for some of you this will be quite primitive. I am basically trying to make game in which the chracter (player) is walking towards the point where was clicked. And i wanna ask what would be the simpliest way to make it follow the road and not going through fences, buildings, etc.
Preview (bad quality)
You could just make the player character go straight from A to B with some collision on the fences so they don't walk right through. This has the downside of not always working (like when the only path involves walking around an obstacle) and of course requires collision detection to be implemented.
The other method is to implement a simple grid-based pathfinding algorithm such as A* mentioned before. A* isn't the easiest algorithm to learn though for an absolute beginner, at least in my opinion, so it helps for sure to watch a good tutorial on the subject.
Sebastian Lague made a great video on A* pathfinding which can really make the algorithm a lot easier to digest.
You need to implement path finding and considering walkable / non-walkable areas. One frequently used algorithm for path finindg is the A* (A star) algorithm.
I have an XNA zombie survival game, where the player has to hold out in a building and zombies come at them by waves. Zombies initially target barricades to get to the player, and then target the player once they break down the barricade.
Here is an image of the game so far. Walls (indestructible) are in black/grey, barricades are in brown:
UPDATE: I have made a lot of progress so far in my understanding of pathfinding, but still no dice. The above picture shows my current grid/node system.
As you can see, outside the "arena" there are very few waypoints. The zombies need to get to their nearest waypoint on a road, so they can then head towards the barrier (the top road still needs a barrier, I know).
Once they break down the barriers they need to use pathfinding to find and follow the player around walls and obstacles, so there are a lot more waypoints.
I am currently storing each of the grid points in a Microsoft.XNA.Framework.Point array. I have tried so hard to implement this with this article which I have referenced so much, but my system and his are completely different and I can't find a way of making it work. For example, the article's system looks one grid unit in each direction to look for a node neighbour. Seeing as the waypoints outside the arenas don't have node neighbours right next to them, the system fails.
XNA is a dying framework and there is no usable articles/tutorials on pathfinding so I really need some help here.
With an a* style pathfinding algorithm, a grid based game level is ideal, as an array of data provides the a* algorithm with what it needs to determine an optimal path.
When you move away from grid-based games, you need to get a little more clever. Your best option is to create a node based a* pathfinder. This implementation requires you to define "nodes" in your level, that serve as waypoints, in a path. Your algorithm utilizes the pre-defined nodes, in a modified a* implementation, to determine the optimal path.
You can even generate these waypoint nodes programatically based on your level. I wrote an implementation in unity described here .
Beyond this, you can look into Navigation Meshes. This technique involves calculating or pre-defining polygons in your level that allow movement. This is a bit more involved, but produces much better results.
I want to slice a mesh object into at least five parts. I've done some research and some people on here have cloned objects when sliced and just instantiate two objects from a single slice?
I'm pretty new to Unity and C#. So any beginner tutorials on where to start or where I can read for learning how to cut mesh would be nice. Like what functions/methods should I be looking into? What methodology is behind cutting mesh?
From my understanding, I haven't seen any tutorial or asset that actually cuts triangular mesh? If there is, how is it done? What is the logic behind it? I guess I need help understanding the logic behind it and how to get started or what I should look into?
Cut mesh in realtime I mean.
EDIT:
Attempt at understanding and playing around with code:
I used the fake slicer 3.0 (http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/) and included in the sample, they have a capsule that the slicer works on.
If I added a cube or another capsule with rigidbodies properties and collider property, the slicer (aka plane) only clones the object and doesn't slice it off. Why is that? How can I manipulate the code above to work for all kinds of objects?
I get this console error and I don't know what it means:
UnasssignedReferenceException: The variable cutplane of 'Slice_mesh3_js' has not been assigned. You probably need to assign the cutplane variable of the Slice_mesh3_js script in the inspector.
Have you tried the turbo slicer asset?
https://www.assetstore.unity3d.com/#/content/4169
There is a demo in their website.
There are ways to achieve what you want, however the noted asset could be the easiest one.
Worth looking assets for slicing, breaking apart:
Fracturing & Destruction https://www.assetstore.unity3d.com/#/content/9411
Shatter Toolkit https://www.assetstore.unity3d.com/#/content/1017
Also you can:
Use your preferred modeling program and model the object in parts
and with an animation slice the object as a result of certain
action.
Programmatically disappear the complete object and appear
the slices using maybe a particle system to improve the effect.
You can see new one here http://u3d.as/qSN
This asset has very fast algorithms for 3D models and in comparison to its alternatives, it have much more clean code.
It supports asynchronous slice if you are not happy with speed. But my tests shows that it is not necessary, it is fast enough to do it in main loop.
It slices colliders converting them to MeshCollider-s.
And it is easy to customize.
I just started using the Farseer engine and so far it's been pretty easy to understand and implement in my aps. I was wondering if there was a way to put a control into a different "world" so that I can manipulate the gravity of just that object but allow other objects to stay at the default world gravity. Does anyone know how to accomplish this or know of any resources that might help me?
Thanks,
Tom
The idea to change gravity for specific objects is a bit unusual, as gravity normally is a global constant in a physics simulation (unless you are using space stuff).
I don't know Farseer engine but I assume gravity works the same as in other physics engines.
Usually in physics to manipulate just one object's 'gravity' you simply lower it's weight/mass (and air friction?). Or even give it a slight upward force (a negative to gravity).