Hot answers tagged

19

Generally it is true, depending on your view point and in which direction it has moved, as well as the viewing angle. Note how in the first camera view, as the Red block is perpendicular to the camera view, the object seems to be twice as large in a perfect 1:2 ratio (Note the arrow pointing that it hits the edge of the view after being moved twice as close)...


17

You want a data-driven approach almost certainly unless your game is going to be completely un-expected and/or procedural generated to the core. Essentially, this involves storing information about your weapons in a markup language or file format of your choice. XML and JSON are both good, readable choices that can be used to make editing fairly simple ...


15

A Poisson-Disk sampling distribution will allow you to select random points a minimum distance apart. Your situation is similar to this question, but since your trees aren't idealized points you'll need to change the distance checking as follows: the distance between a potential new tree & an existing tree, must be less than the sum of their radii. ...


9

An object twice as close does appear twice as big. It is a consequence of Thales's Theorem and it is true in the real world. One could argue that Thales's Theorem is the core mathematical tool behind perspective projection and what's known in the graphics pipeline (OpenGL or DirectX) as perspective division. It a theorem you should definitely know, and ...


7

Actually that's pretty much true (if you move an object twice as far away it looks half as big) but it obscures how the visual size of objects should change as the viewers moves. Specifically, objects appear to get bigger faster the closer they are. That's because the viewer covers half the distance a lot faster when the object is close, compared to when the ...


7

(I'm sorry to submit the answer instead of a comment, but I don't have rep yet.) Vaughan's answer is great, but I'd like to add my two cents. One of the main reasons you'd want to use XML or JSON and parse it in runtime is to change and experiment with new values without having to recompile the code. As Python is interpreted and, in my opinion, pretty ...


6

I need a tutorial that does not skip to explain any lines of code. It should also include different independent objects moving/rotating (most tutorials use only one object), as well as imported 3d objects Arcysnthesis is the best modern OpenGL tutorial I know of, using imported objects doesn't add much to the use of the API, and it's usually API agnostic. ...


5

Keep Bullet functionality in the Bullet class. This just sounded like nails against a chalkboard to me: During the iteration, it checks what type of object it is, such as Bullet etc. Once it has checked this, it will calculate where the bullet should move to next based upon the Velocity property. Aaagh. D: It's not the base Entity class' responsibility ...


4

Data-Driven Design I submitted something like this question to code review recently. After some suggestions and improvements, the result was a simple code that would allow some relative flexibility on weapon creation based on a dictionary (or JSON). The data is interpreted at runtime and simple verifications are done by the Weapon class itself, without the ...


4

Simple Answer Use a class to load the original prefab from Resources.Load(string prefabPath, typeof(GameObject)); Store this returned prefab into a resource pool class by path key. For instance: Dictionary<string, GameObject> prefabLookup; You can then grab the original prefab anytime you need it. Use a helper method to automatically load at ...


3

Wavefront obj files usually are combined with material files (.mat) which define the textures used. The meshes of a model are divided in different material groups. Each material tells you which textures to use and other information of the mesh. In your case, there are separate meshes on the model. These meshes are head, body and hands. They all have their ...


3

I like to use a callback based input manager. The Player class calls the static register method of the input manager with the input to register (either some hard coded values like W or an alias like Forward) and a method to call back when the event happens. In Java this will probably be programmed with an anonymous overloaded object of a callback class, or ...


3

How about instead of threads or continuous looping, you use an event system to notify listeners (people who care about when the timer/action is 'finished'). Edit: This pattern is called the observer pattern. There are many ways to implement the function callback system, including delegates and function pointers. It is up to you which one you use, though ...


3

Do you really need two ways of deleting an object? If there is no concrete reason for an object to be able to destroy itself, you could scrap the WorldObject::removeFromWorld() method entirely. Otherwise, your compiler will probably allow you to call a method that destroys the caller, but I wouldn't say this is a good idea. Consider what could happen if you ...


3

From what I understand you want something like this. You can change the name and value from the Grid-object. It refers to the same object as in the array. So this works 'out of the box'. Is this what you mean? public class Game { private static final int LENGTH = 32; public Grid[][] grids = new Grid[LENGTH][LENGTH]; public Grid getGrid(final int row, final ...


3

For me it should be done in this way: What we need: A throw point - a Transform attached to mode's palm of hand Throw animation (Option A ) A event that will be fired during the throw animation, at the moment that the grenade should leave player's hand / (Option B) Or the infomation about how much time it will take from the beginning of the throw animation ...


3

Before I go into the code, I want to go over how Lerp works. Vector3.Lerp(Vector3 start,Vector3 end, float fraction); The above code will return a Vector3 that is between the start and end positions at some fraction of the way along a line between two points. So: transform.position=Vector3.Lerp(Vector3 start,Vector3 end, float t); If t is 0.5f, this will ...


2

You could just add a script component that simply contains an int for an id with the start method containing some logic to initialize it to a unique value. Once you do that, you can use a hash table for storing and accessing the gameObjects with their ids.


2

Since you're not actually working in 3D space, we can assume the sprites never rotate (rotation can be simulated with skewing, etc.) This simple constraint makes it pretty easy to get somewhat accurate numbers on what the size should be depending on distance from the camera. First, you need to understand how 3D objects are rendered. Even though a camera ...


2

I'll share my design as of current implementation I did for my game. ObjectPool & Managers For objects whether it's enemy objects, collectable items, powers-up, effect (more like particle), etc, I managed them through my own implementation of ObjectPool as you will know roughly number of instances you would need in the game for certain time, so it will ...


2

As far as I know, if you don't use the object after it's destroyed there is no problem (otherwise you will be accessing a deleted object which is probably undefined behaviour). You could avoid the trouble of managing the memory by having std::unique_ptr<WorldObject> instead of WorldObject* and you would remove from the map simply by calling objectList....


2

You can split this into two stages: Firstly generate some pinecones with such minimum distance between them that you need: On second stage add some pinecones next to those placed already: That way you will have have some single pinecones and some pinecones clumps, but all of those will be separated well apart. You can tweak 1st stage to use slightly ...


2

You need to enable some kind of z-buffering: first render unobstructed units, then buildings, then units that are obstructed (complete or just partially) by buildings and then the ground. If you render them in this order make sure no pixel is overwritten: do not draw over a pixel that has already been drawn, else only the terrain will render. Flush the ...


2

You can change the color of the same material, on different objects, from script. Do the following: Create a materialand assign it to the target game object. Create a new C# script, and copy in the following code. Inside "parent" the objects whose color should change is placed in the unity editor. using UnityEngine; using System.Collections.Generic; ...


2

With transform hierarchies (trees), the normal method is to work your way up or down the tree, applying any transformations of the parent to the child, at each level, till you have processed everything. Given you aren't concerned with issues like rotation/orientation or scaling, i.e. you're purely interested in translation, it's very simple: //...do your ...


2

To figure out what is going on, I started looking at the code that moves the balls. In this case it is physics (fisicas). I see two coditionals where you stop the ball: if (this.y + this.radio < GROUND) { this.yVel += this.gForce; } else if (this.y + this.radio > GROUND && this.yVel > MIN_ACCELERATION) { this.yVel *= -this.friction; ...


2

If you have a set of bounding boxes and the first and last one shouldn't get moved, then you can create a line out of the center points of these two and line the ither center points up with it. So, the x position of the center of a bounding box given the line defined by A and B and the y position is x = (B.x - A.x) * (y - A.y) /(B.y - A.y) + A.x So if you ...


2

When you have an array of type Entity then you can only call methods on the entries which are declared in the class Entity. If you want Human and Zomby to have different implementations for that method, then you can declare that function as virtual in the Entity class. You can then override that implementation in both sub-classes. That means when you call ...


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