Tag Info

New answers tagged

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 ...


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 ...


0

1000/65536 == 0.0152587890625. Just use increments of 0.015 or maybe 0.015625, because it has accurate binary representation (2**(-6)). With the latter you'll get 1000/(2**(-6)) == 64000 unique positions.


0

Maybe you should change You'r approach to something simpler. What I would do; Keep your Z depth thing, but keep a list of what you render. Order that list based on the z Depth value, and render objects in the order of the list. Hope this can help. People always tell me to keep things simple.


0

I have done something like this and works great.. background scrolls from top to bottom. To make black bar disappear add an offset to size of second background initiate() { offset=2 ; bg1=new Sprite(backgroundImage); bg2=new Sprite(backgroundImage); bg1.setSize(width, height); bg2.setSize(width, height+offset); //ADD AN OFFSET HERE YOU ...


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, ...


0

The last time I faced something like this I came at it from a very different direction: I didn't use a global cooldown at all. After a shot was fired I set a reloading timer on that barrel. Every tick the reloading timers were decremented. (Watch out for roundoff errors if you're using floating point--I simply used a certain number of game ticks.) When ...


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 ...


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

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 && ...


0

Since you mention voronoi, i'll give my c# voronoi implementation private void Voronoi(int[,] points, int minDelta) { for (int i = 0; i < wid; i++) { for (int j = 0; j < hei; j++) { float minDist = 999999999f; float minDist2 = 999999999f; float minV = 0f; for (int p = 0; p < ...


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 ...


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 ...


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 ...


0

Assuming you've correctly assigned a valid prefab GameObject to your 'bulletPrefab' variable, it looks like it should work. You say the "bullet still doesn't fire". Have you ensured that the AddForce method is being called i.e. add some debugging to that Fire() method to ensure it's being hit. The only other thing I can think of is that you need to be ...


0

public class ShootBullet : MonoBehaviour { public GameObject bulletPrefab; float attackSpeed = 2f; float cooldown; void Update () { if(Time.time >= cooldown) { if(Input.GetKeyDown (KeyCode.Space)) { Fire(); Debug.Log ("Shoot"); } } } // Fire a bullet void ...


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 ...


0

This was simply an error with her and my Unity versions being different. By updating my version of Unity, that solved the issue. Apparently files need to come from the same Unity version to be compatible!


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 -= ...


0

Use transform.TransformDirection() along with Vector3D.forward (or .up or whatever). TransformDirection() will convert the 'forward' direction of the player to that direction in global space. EDIT: oops you want to transform the direction the other way, from world space to local space, not local to world. Use InverseTransformDirection() Another simple ...


0

You want to look into parsing, which is a very well documented field. To start off simply though, you might parse the file line-by-line, stripping '#' to the end of the line, and stripping any padding whitespace. This solves the issue of "its not very flexible because you just have to put one tiny whitespace in front of the square brackets". You can then ...


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 ...


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 ...


0

Drop in a couple breakpoints and see if either of the MoveHandler condition blocks are actually visited in the following code : if(MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.RIGHT); else if (!MoveHandler.facingRight) -> orbControl.SetDirection(BasicAttackOrb.LEFT); Since those lines are responsible for changing the ...


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 ...


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. ...


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 ...


0

From my experience recently in doing a few 3D animations, I found it very simple to just split up the animation into 3 separate clips. That way I felt that it was quite intuitive and easy when creating transitions between each animation clip in each stage of the overall animation. You also have a great deal more control over the animation transitions using ...


1

Sounds to me like what you need is to define a box in the middle of the screen, and only if the car moves outside of that box then the camera will move. That way the car has a bit of freedom to move without the camera moving, but as soon as it gets too far away from the center of the screen the camera does follow it. This is similar to the technique used in ...


1

There are lots of ways to do this, though MoveTowards seems reasonable for your purposes. Essentially, you'll want to determine some speed you want the camera to follow the car. Let's say that's float cameraFollowSpeed; Then you need to adjust that to be framerate independent with Time.deltaTime So now FollowCar's Update() your code is something like ...


4

First its good to note the difference between Colliders and Triggers Colliders - generally are intended to represent physics interactions, so objects "colliding with them" should not pass through one another. As opposed to... *Triggers* - as the name implies, "fire" off an event but don't carry the typical physics body interactions Triggers and colliders ...


2

Rather than rotating a sprite, I would suggest you try multiplying the sprite's x scale by -1. This will flip the sprite without having to rotate anything.


0

Hold a reference to your Camera, then set its localEurlerAngles to Vector3.zero. Camera yourCamera; void Start() { yourCamera = GetComponentInChildren<Camera>(); } void Movement () { anim.SetFloat ("moveSpeed", Mathf.Abs (Input.GetAxisRaw ("Horizontal"))); if (Input.GetAxisRaw ("Horizontal") > 0) { transform.Translate ...


2

Using a 2D tile array for your world/level generation and representation will definitely simplify things. For example you could internally represent your world in a grid of tiles and take it from there : using System; using System.Collections.Generic; using System.Text; namespace Tiles { public class Vector2 { public int x; public int y; ...


3

If you're using a grid, you shouldn't be using Unity's physics for collision detection - use the grid. Get your position on the grid then do something like this: public bool GridCast (Coordinate Position, Coordinate Direction, int Length) { for (int i = 0; i < Length; i++) { Coordinate Check = Position + Direction * Length; if ...



Top 50 recent answers are included