Hot answers tagged

40

Use a boolean flag. In the example shown, you'd modify the code to be something like the following: //a boolean flag that lets us "remember" if this thing has happened already bool thatThingHappened = false; void Update() { if(mousebuttonpressed && !thatThingHappened) { //if the mouse is pressed and that thing hasn't happened yet ...


22

A common approach is to have a component-based approach where the base-class "Unit" just implements the most basic aspects all units have in common, while each unit then has a list of multiple component-objects which say what it can do and how it does it. For example, a tank might have the components Mobile, Destructible, Attacker, an immobile turret only ...


20

Should bool flag not suffice or you wanted to improve readability* of the code in void Update() method, you could consider using delegates (function pointers): public class InputController { //declare delegate type: //<accessbility> delegate <return type> <name> ( <parameter1>, <paramteter2>, ...) public delegate void ...


13

Have you looked into entity component systems and event messaging strategies? Status effects should be components of some sort which can apply their persistent effects in an OnCreate() method, expire their effects in OnRemoved() and subscribe to game event messages to apply effects which occur as a reaction to something happening. If the effect is ...


12

Create an engine module/folder/whatever, that contains everything that can be generalized and is 100% independent from the rest of the game. This would include some code, but also generic assets that are shared among games. Put this engine in its own git repository, which will be included in the games as a git submodule That's exactly what I do ...


11

RobStone is on the right track, but I wanted to elaborate since this is exactly what I did when I wrote Dungeon Ho!, a Roguelike that had a very complex effects system for weapons and spells. Each card should have a set of effects attached to it, defined in such a way that it can indicate what the effect is, what it targets, how, and for how long. For ...


7

The only real problem you'll be fighting is floating point precision; only 6 digits. When you accumulate floating point error over astronomical distances, you get astronomical inaccuracy. This causes distant bodies to rapidly alternate between two or more places from frame to frame. It's likely you'll have two coordinate systems and, in most cases, you'll ...


6

At some point an engine MUST specialise and know stuff about the game. I will go off on a tangent here. Take resources in an RTS. One game may have Credits and Crystal another Metal and Potatoes You should use OO concepts properly and go for max. code-reuse. It's clear that a concept of Resource exists here. So we decide resources have the following: ...


6

If what you want is to bypass the floating inaccuracy caused by single point precision problem, for the sake of creating bigger environments for your game, then it depends on what you are willing to accept as a solution. Let's start by making this clear: it is impossible to alter the coordinate system at the inner core of Unity. So, you can't use ...


6

First, you should not have a strict 1-1 mapping of Components to Systems. It's unclear to me from your question if that's the case already. You may very well have singular systems that use or interact with numerous components. Rendering, physics, AI, etc. are all Systems (they perform a cohesive set of updates and logic) but interact with many Components. A ...


6

Short version: no, your job as an engineer is to evaluate all applicable solutions to problems before choosing a solution Long Version: "ECS" is an overloaded term. It had a somewhat clear definition at first but it's been overly muddled since. It doesn't matter much, though, since the answer is the same either way: every architecture has pros and cons. If ...


5

That's a question that frequently pops up. I will take the liberty to forward you to another fairly detailed answer I already gave to the same issue, instead of just repeating it here: Is a custom coordinate system possible in Unity From there, what I would suggest the most is that you read the amazing paper at: ...


5

FXC or D3DXCompileShader or D3DCompile to compile basic HLSL vertex/pixel/... shaders (single entry point, just like GLSL). Then create shaders from the generated shader blobs using API functions such as CreatePixelShader (D3D9) or CreatePixelShader (D3D10/11). Then apply these shaders with SetPixelShader (D3D9) or PSSetShader (D3D10,11). To transfer ...


5

Your design contradicts object oriented programming. In object oriented programming (which is the core of the C# language) you combine data and logic in a class. This means a class is a construct that defines all of its properties (cost, level, children in your example) as well as what it can do. Hence you should of course combine those two parts, ...


4

It's OK to have component dependencies. And the more explicit the dependency the better. There's nothing worse than dependencies hidden behind useless layers of indirections. Your case doesn't look like a dependency hell to me. No circular dependency or unclear ownership of data: consider yourself lucky! Now I still believe that you need to reverse your ...


4

One way of handling this could be to implement some form of graph system: http://en.wikipedia.org/wiki/Graph_%28mathematics%29 Or as a state machine: http://en.wikipedia.org/wiki/Finite-state_machine In both cases you describe your quest states (stages) as nodes, and the edges/transitions as the actions that can be performed to move from one state to the ...


4

Disclaimer: artemis-odb dev here. -Changing the Entity System, i know of Artemis, but it would be great if you could point me at something else for Java if you know a library that does it better. I'm not sure whether you're referring to vanilla artemis or artemis-odb, but the latter improves on performance considerably with regards to mutating ...


4

I'd move all those UI constants to a centralized file. It doesn't matter if they are only used in one class or not. The reason is that if you ever want to adjust that type of stuff, it is nice to have it all in one location. You don't want to have to muck with a dozen different classes just because you decided you wanted to change the overall look and feel ...


4

For synchronisation, you need to decide who (your code, animations, or neither) is the timing authority—the "beat" that everyone else "dances" to. Different arrangements suit different games: Animations are the timing authority (your current setup) The game code may trigger animations. When animations reach certain points, they raise events (e.g. ...


4

You're thinking in very static terms. Just because an object is half a world away doesn't necessitate any issues. If entity coordinates are stored relative to chunk rather than relative to world, this is trivial to achieve. Welcome to the way you'd have to do it if you were writing a voxel world in native code. So let's assume a concept called locales. ...


4

I doubt that there's a way to change the coordinate system Unity uses internally for its transforms/physics/etc. Not without recompiling the engine source at least. But that may not be necessary to get both the precision and scales you need. Kerbal Space Program is made with Unity, and plays out over interplanetary scales. The developers have been great ...


4

I've worked quite a bit with Mecanim in Unity, and feel I have a quite good understanding of how it works. Like you say, blend-trees are almost definitely the way to go for doing locomotion. Blend-trees are generally for when you want to continously blend animations to create the final output. Like give the player the control of how fast the avatar is ...


4

A lot of games use a component-based system for entities which is where a bunch of behaviours and abilities can be added to a more generic unit type rather than being coded as part of the entity's class (or equivalent).


4

This question is a bit broad, but a few things... 1) You could create a CLASS for weapons, and have the character object own a 'weapon' object, and then you can add in, say "Weapon.damageBonus" to damage dealt 2) Your "Attack" function returns a "Characer" object. I believe you want to return an int or double (or float if for some reason you need a ...


3

Rather than hard-coding your data in Javascript, why not use JSON. It's always a good idea to separate your data from your program, and splitting out item definitions into JSON files would be very clean I think. Node even let's you use "require" with JSON files, how handy: How to parse JSON with node Databases are a great technology to learn if you haven't ...


3

I can give one small piece of advice. Don't do this in your render loop: viewMat = getUniformLocation(sp, "viewMat"); modelMat = getUniformLocation(sp, "modelMat"); projMat = getUniformLocation(sp, "projMat"); maxIterLoc = getUniformLocation(sp, "maxIterations"); centerLoc = getUniformLocation(sp, "center"); scaleLoc = getUniformLocation(sp, "scale"); ...


3

The answer to the question "Is it possible, or even feasible, to have graphics engine completely decoupled from game logic?" is "yes". I would say it is even "advisable". But in general, you'll find a lot of your game ends up tied to the engine you choose for other reasons, like input handling or use of their facebook integration or other cross-platform ...


3

I think the Observer Pattern may fit here. Instead of sending a message to your button, let your button observe some component.


3

I believe UE4 network architecture is roughly the same as in prior versions of Unreal Engine, perhaps with minor refinements, and goes back to the very first version of Unreal Engine. This is a client-server system with very little difference between Unreal server and clients. They run the same game simulation code, potentially even the same executable with ...


3

Engineering is all about having to prototype machines in order to see whether a concept works. There is some minimum amount of labour required to test any such theory in working form - usually quite a lot - and until that labour's been put in and the system is in working form, it is just a theory. An engine is largely complex (especially in the temporal ...



Only top voted, non community-wiki answers of a minimum length are eligible