Tag Info

Hot answers tagged

5

Indeed, the values stored in the z-buffer are not linear to the actual z coordinates of your objects, but to their reciprocal, in order to give more resolution to what's near the eye than to what's closer to the back plane. What you do is that you map your zNear to 0 and your zFar to 1. For zNear=1 and zFar=2, it should look like this The way to ...


4

Your code is very scrambled. You have all your time relative variables inside the shooting loop. and the instantiation code too. Why? Why not simply make it like this : void ShootBullet() { Rigidbody bPrefab = Instantiate (bulletPrefab, transform.Find ("Bullet").position, Quaternion.identity) as Rigidbody; bPrefab.AddForce (transform.up * ...


2

After some more testing, it appears the problem was the Start() method. Apparently, for whatever reason, the code was being executed as follows: orbControl instantiated -> SetDirection() -> Start() Thus, because of this, direction remained 0. So, I changed Start() to Awake(), and all's well. It appears to me after more research that this is the main ...


2

Sprite Sheets with a Uniform Grid The easiest form of sprite sheets, are sheets that use a uniform grid to lay out the individual sprites of your object. Your sheet is essentially a grid with a certain number of rows and columns of cells. Each cell contains a single sprite. Using a uniform grid, means that all cells have the exact same dimensions. ...


2

I once needed to do this, to have several "animations" play off one after the other, here's my approach : 1- Create an empty gameObject, let's call it SceneControl that will be the parent of everything you need animated in your scene, for example Trees, which will contain all the trees, Clouds, that will contain all the clouds, Text, etc.. 2- Set all the ...


2

You're on the right track. However... Try O(n*m) runtime is typical with something like this. Your implementation is a bit excessive, however. The real question is, What is making your O(n*m) algorithm take so long? Why bother to run through every map cell for each influence? It would be faster to have each starting influence also specify some random ...


2

In the frame that bulletCounter become 3, Time.time will be less than gunGlobalCooldown because this line of code: gunLocalCooldown = Time.time + 0.12f; gunGlobalCooldown = gunLocalCooldown + 0.8f; so the boolean canShoot will be set to false, and this if if (Input.GetKey (KeyCode.Space) && Time.time >= gunLocalCooldown && ...


1

Allow me to offer one interesting consideration for mobile devices where 2D performance can actually lag behind low poly 3d models: 1) Fill rate can cause quite a bit of performance trouble when dealing with many sprites on screen at a given time. 2) Texture memory requirements for a fully fleshed out 2D game are actually much higher if you're using frame ...


1

Coroutines are the best performance-wise. I.e. void Start () { //Starting the coroutine StartCoroutine (Shooter()); } IEnumerator Shooter () { if (Input.GetMouseButton(0)) { //Shoots the bullet Rigidbody bullet = Instantiate (Bullet).GetComponent<Rigidbody>; bullet.AddForce (Camera.main.transform.forward * 10, ...


1

So this doesn't produce exactly the behavior you asked for but I think it might be what you're looking for anyway. This code (syntax not exact as I don't use c#) would allow someone to sustain a fire rate of one bullet per 0.5 seconds indefinitely, but fire bursts of up to 3 bullets at a rate of one bullet per 0.12 seconds. gunBurst=0.12f gunSustained=0.5f ...


1

Instead of iterating over all plates, consider only those empty cells that could possibly be filled: namely those that are adjacent to at least one already filled cell. Your algorithm could then become something like this: 1) Keep track of all unfilled cells that have at least one adjacent filled cell. 2) Select one of these unfilled cells. 3) Select one ...


1

You will need a zombie class. public class Zombie { public int x, y; public Entity(int x, int y) { this.x = x; this.y = y; } public void tick() { //code to control movement and such } public void render() { g.drawImage(zombieImage, x, y, null); } } I'm not sure which class you are showing in your code but you will need to make a zombie ...


1

I don't fully understand your question. But, if you want to move something forward, what I would do is something like: this.transform.position += this.transform.forward * moveSpeed; Whereas, moveSpeed is the speed at which you want your unit to go forward. To go in the opposite direction that you are facing: this.transform.position -= ...


1

Given that top left is at 0, and each tile is square with length 10: int squareClickedX = clickPosX / 10 int squareClickedY = clickPosY / 10 So, if clicked on x23, y12 int squareClickedX = 23 / 10 int squareClickedY = 12 / 10 results int squareClickedX = 2 int squareClickedY = 1 Means that you clicked Was this any good? This is quite common way ...


1

Using an atlas: You can pack the left and right versions into a single texture for each sprite, and only swap UV's based on the player's direction. Although you may put only left/right images into the textures, will your modders? A few descriptors to think about: bool AutoFlip; //Swap UV's based on L/R? bool ReverseTextures; //Reverse standard ...


1

You can use an Orthographic projection matrix to transform your vertexes. Then you can simply provide your triangle verts in terms of screen pixels, e.g.: a vertex at (0,0), one at (10, 0) and one at (5, 10). Here's another reference of OpenGL matrices, with a lot of maths. Make sure to do a search for "OpenGL orthographic projection" and "2D drawing with ...


1

I assume you assign a Prefab to public GameObject missile in the inspector. When you try to destroy missile inside of your OnTriggerEnter2D method, the error message does make sense, since you're trying to destroy a prefab and not an instance. Instead of trying to destroy missile, you should destroy the object that collided with your GameObject. So, ...


1

I have a couple of suggestions Avoid Allocations and Copies A lot of your code has unnecessary allocations and copies. Instead of filling a vector with push_back, try pre-allocating the vector and setting the data there. You have a fixed maximum number of intersection points, so pre-allocate a vector of that size. Do a Simple Broadphase Before you do ...



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