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.
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.
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 am building a ship simulator that will produce accurate position and orientation values for a prototype hull design in some defined sea-state.
In terms of programming, I have 2 arrays (vectors) in MATLAB containing the position and acceleration values for x, y, z, yaw, pitch and roll. Because the visualisations in MATLAB are a bit crude, I am planning to write a simple server within MATLAB to send these values (at 200Hz) using sockets to another program. The sea is modelled as an array of vertices (think of amplitude snapshots at different timesteps on a sine wave).
So my question is, what's the easiest way to animate a 3D boat and some textured water on screen?
I am only interested in the graphics engine. I have no need for sound, physics, collisions, interface (keyboard, joystick, etc). It should be able to run primarily on Windows, but it would be nice if it could run on Linux and Mac OS too (depending on the additional complexity involved).
Not an expert, but few leads are
vtk, portable and integrates, regarding complexity look at sample code
comparison of engines in a related so question (and online database it links to)
The above might be called complex and bloated if compared to low level API such as OpenGL, but you have to define what kind of simplicity are you looking for.
For example, "easiest way to animate a 3D boat and some textured water" could mean that you write a clean low level interface directly on top OpenGL API; but as with anything graphics, and especially 3D, I do think that it will not be long before you will start thinking about lights, camera movement, interface, etc... and then you will probably wish for a richer environment.
So, the question is also if you want something really slim and then handle all sort of low level tasks or something that might include much more then you will ever need, but have lot of resources and shortcuts available.
Now, that my rant is finished - I am sure that you'll be able to find an exact example of animation that would take two mesh objects (sea and ship) in OpenGL and display them on screen in any decent OpenGL tutorial.
The easiest way would be to use PANDA3D. it uses python and is quite complete.
I've found OpenGL pretty easy to use in the past, or if you're on a Windows environment there's Direct3D too.
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
Ok, so I ended up writing my own game engine based on top of XNA, and I am just wondering what else I need to make a complete engine.
This is what's in the engine:
Physics (Farseer Physics)
Particle Engine (Mercury Project)
2D Cameras
Input Handling
Screen Management (Menus, Pause Screen, etc.)
Sprite ( Animation, Sprite Sheets)
And XNA stuff like Sound.
Am I missing anything that might be crucial to a game engine?
You're approaching it in an upside-down manner.
What should be in your engine is the following:
All the code that turned out to be common between your first and your second game.
First, write a game. Don't write an engine, because, as you have found out, you don't know what it should contain, or how it should be designed. Write a game instead.
Once you have that game, write another game. Then, when you have done that, examine the second game's code. How much of it was reused from the first game?
Anything that was reused should then be refactored out into a separate project. That project is now your game engine.
This doesn't mean that you shouldn't plan, or shouldn't try to write nice code. But make sure you're working towards something concrete, something where you can tell a good implementation from a bad one. A good implementation of a game, is one that works, is fun, and doesn't crash. Write your code to achieve those things first.
A good implementation of an engine? That's trickier. What's a good implementation of a renderer? Of an AI framework? Of a particle system? Ultimately, the only way to determine whether you have a good engine is by seeing how well it works in an actual game. So if you don't have a game, you have no way to evaluate your engine. And if you have no way to evaluate your engine, you have no way of judging whether any of the code you're writing is actually useful.
A theme or market for your engine. If you're doing anything beyond basic your basic graphics engine, you'll want to concentrate on a market for your engine, like RPG, strategy, puzzle, platformer, action, or FPS (ok, not FPS).
This will help you point yourself in the direction you need to go in order to make further enhancements to the engine without asking us. An engine like say, the Unreal Engine, can do multiple things, but what it tends to do best is what it's made for, FPS games. Likewise, you should tailor your engine so that it suits a particular field of interest, and therefore is picked up for that type of gameplay.
You can make it general to a point, but realize the more generalized your engine is, the harder it is to program, both time wise and skill wise. Other programmers are also less likely to pick up a general engine (unless that's all there is) if a more specific platform is available. Or to just write their own since modifying a generalized engine is about as hard as creating your own.
A few more things:
Path finding - very useful for AI
AI - possibly - depends on how generic you want the engine to be.
High scores
Replays - makes high scores much more interesting, as you can actually watch them.
A couple ideas:
Artificial intelligence (perhaps just simple AI utilities, like pathfinding algorithms)
Saving all or part of the game state (for suspending and restarting at a later time or saving high scores).
I think that you covered the general requirements of a 2D engine. The only thing I would miss in that list would be:
GUI Library
Also to make development processes easier:
Script Engine (LUA, C#Script, ...)
Dynamically Refreshed Assets (see Nick Gravelyn's Blog Entry)
You might also add another layer on top of XNA's existing stuff:
A quite bareboned Network/Lobby implementation
More abstract handling of multiple controllers (DropIn/DropOut during gaming sessions, like see Resident Evil 5 Coop) - maybe event-based
Finally you might add some "ready2use" shaders. Maybe get some inspiration from the discontinued FaceWound (from the "Garry's Mod" developer).
It depends on the game, but another thing often needed is a good networking framework.
Many modern games, including 2D games, seem to have some form of networking in place.
Animation framework so that you can say: take this sprite, move it in this direction, folowing this path using this speed, acceleration and such
Basic GUI system. Don't implement a whole Windows, but basic things like a pointer and a button, and such - keep it basic
Debugging component for displaying FPS, numbers of sprites and such
Also a good thing is to make some games, and then you will quicky see what things you repeat doing for each game, and then look into how to can get that into the engine.
2d lighting system is a good advanced feature. You can use Krypton for that.
Map editor. Or even better support any tile-map format, compatible with "Tiled Map Editor". So you can just use Tiled.
Scheduler/Timer for game actions.
Screen wipe effects such as page turn, fade out, etc. to make nice transitions between screens.
Game layers with build in parallax would be usefull too.
In game console to process commands or scripts without restart.
Easy load for texture atlas as sprites or animation.
Nice Work,
We (me and some of my friends) are working on a game engine too actually,
We've already got all what you mentioned but moreover we've got the following.
audio manager : a simple class to handle background music and sounds
effects in XNA.
video manager : it's not complicated, a simple class to handle video
playing in XNA.
effects manager : is responsible for stuff like bloom, blur,
black/white colors .. etc.
Good Luck :)
3d Acceleration should be in a 2D engine.
Using the 3d hardware that most people have these days is the best way to get amazing performance for your 2D games...
Good collision detection is very helpful. If you implement it efficiently, it really reduces the time required for every frame. Besides that, in my engine (for Pygame) I have a method of separating the main screen into a number of subscreens, which I find useful.
Depending on the target game type, include Navigation Graph(s) with node and edge annotations. (Good for many games, but not so much for the token side scrollers that are made with 2D graphics engines)
A component to generate them (via a flood fill algorithm).
Be sure to include all of the major path finding/planning algorithms (A*/Dijkstra/etc.) to traverse those graphs.
The pitfall of this is that you will have to define what a 'map' is for the engine, which might limit users of the engine.
Related things:
Location based triggers (player enters an invisible circle and something happens - queue cutscene, start ambush, etc.). I would say provide a base class for the trigger and implement some basic ones to show how it's done (ie. weapon pickups etc.)
Some game engines implement networking (though this is kind of part of the 'xna stuff')
The most useful thing to include above all else would be tools to easily use your engine. Maybe use your engine to create the tools. I'm sure you would find a lot of flaws that way.
Simple pixelperfect collision detection. NOT Farseer Physics. Simple drawing routines like drawline, drawcircle etc.
A tile repeat tool. Something that allows the user to add/create a tile, and manipulate the edges for a smooth repeath pattern.
Um. This list is an "internals" list. To make great engine is to make great "external" list.
Look at UE3 for example -- it is here because of great tools. You need tools for world creation, to create optimal packages of resources (it should be in internal list too ;-)), for collision object specification etc.
Plus, to add to Organiccat answer you should decide on tech level. You can go for simple sprites or you can want fancy effects (so shaders are needed, and with this you need infrastructure)