Tag Info

New answers tagged

1

It is impossible to know for certain from the given code what the issue is, but a reasonable guess is that you namesAsset string contain DOS/Windows style line endings, and therefore when you split by '\n' you leave an '\r' at the end of strings. I of course assume that the path you use is only a placeholder for code that reference the user folder properly. ...


1

Last time I was looking at benchmarks for this (quite some time ago), Texture2D.FromStream was actually faster than Content.Load<Texture2D>. The overwhelmingly slowest part of the process, it turns out, is transferring data from disk. When using Texture2D.FromStream, you can load a PNG or JPEG file. These file formats use image-specific data ...


1

//temp helper variable var moveAmount = Point.Zero; if (InputHandler.KeyPressed(Keys.A) || InputHandler.KeyPressed(Keys.Left)) moveAmount.X -= 1; if (InputHandler.KeyPressed(Keys.D) || InputHandler.KeyPressed(Keys.Right)) moveAmount.X += 1; if (InputHandler.KeyPressed(Keys.W) || ...


0

Not a significant one, though this depends a lot on what you're trying to achieve. Keep in mind that Texture2D.FromStream() returns a default format of SurfaceFormat.Color /w non-premultiplied alpha data, whereas with the pipeline you have full control over what you want to do with the texture. The distinguishing feature between the two is flexibility as ...


2

You are assigning the same position at every frame when the related key is pressed. Adding the value should solve the problem. this.transform.position += new Vector3 (Input.GetAxisRaw("Horizontal") * _speedright *Time.deltaTime, this.transform.position.y, this.transform.position.z);


1

It's because of the variable IsOnGround and duration of jump key. Imagine this, no matter how fast you are. Update will be called 60times a second. That makes jump key true for more than a instance. Also it takes player time to achieve lift off making isOnGround true for more than one instance . Hence the inconsistent jump, try switching isOnGround to off ...


0

Starting to log crash dumps are a good start, but it might not tell you the whole story. Your users have a diversity of hardware/network connections and may use the game in ways you may not have imagined. The crash dumps may tell you WHAT the error was, but not what the conditions on the clients or even your server were at the time the crash dump occur. To ...


-1

1) Use Breadth First Search (BFS) to calculate the path http://en.m.wikipedia.org/wiki/Breadth-first_search 2) Highlight path 3) Move the object Pathfinding: http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html


0

Actually this is like any tile based movement from a turn based strategy game. You can simply flood fill the tiles from the selected character to find which should be highlighted. Psuedo code: Set<Tile> getTilesInRange(Character character, int range){ Set<Tile> highlighted; highlighted.add (character.tile); Set<Tile> ...


2

To expand on OP's answer: the crucial difference is the use of FindObjectOfType versus FindObjectsOfType. FindObjectOfType returns a single object. FindObjectsOfType returns an array of objects. Linq's OfType extension method requires an enumerable collection (such as an array), which is why you were seeing that error and why switching calls fixed it.


0

Resolved by changing FindObjectOfType to FindObjectsOfType: var listeners = FindObjectsOfType<MonoBehaviour> ().OfType<iPlayerRespawnListener> ();


0

There are lots of simple functions to realize those curves. (x^2)*40 - (x/8) + 200 This one grows in a smooth curve since I used x^1.5: (x^1.5)*5 - (x/9) + 200 Play around with the values.


4

Long ago I did the math for different growth functions for an RPG (that I didn´t use in the end). I was playing around with five basic growth curves, as show below. The curves are: Red: Exponential. Grows slowly at the beginning, very fast at the end. Blue: Quadratic. Average growth curve. Black: Linear. Green: Flipped quadratic. Grows more slowly with ...


0

What I did in a game (there's slot that displays a sprite that depends on the "element" chosen) is: Set a sprite renderer component on the prefab. Create sprites (not textures) in Resources/Sprites/Elements Set a script component on the prefab Define an private attribute "Sprite[] sprites" In the Awake method use "sprites = Resources.LoadAll ...


0

You can change to texture that the sprite is showing in code by doing something like public Texture2D texture; Sprite.texture = texture; If you want to know everything about sprites please check out this link:http://docs.unity3d.com/ScriptReference/Sprite.html


2

You could use a logarithmic function: Example function: double increment = Math.Log(level + 1); Example output: Level 1 increment: 0.693147180559945 Level 2 increment: 1.09861228866811 Level 3 increment: 1.38629436111989 Level 4 increment: 1.6094379124341 Level 5 increment: 1.79175946922805 Level 6 increment: ...


0

Since these are possible solutions I figured why not ... HP in my experience has always been something that increases very slowly, XP required for next level tends to be the big exponential. I would go with your second example or you could try reducing the 1.17 in your pow call to something like 1.02 for a more gradual increase. You could also consider ...


0

Read the conditional in your code; it says "play idle when not on the ground": if (controller.isGrounded ) { animation.Play (moveP.name); } else { animation. Play(IdleP.name); } (I'm going to assume you just didn't notice that; we're not really here to teach the basics of programming)


0

Well, after poking around, I was able to preview my game by going the the Win8 project in my solution explorer, right clicking it and selecting "Debug". Now my 3D models won't load properly lol. ty for reading, everyone


1

This is a selection functionality but you could easily include your own rules. First, it's important that you define a tag for the selection group. In case there are more than one selection group in a scene at a time, there should be more than one tag defined for the groups. SelectionButton.cs using UnityEngine; using System.Collections; public class ...


3

Fly along circular arcs You start at x1, moving in the direction v1 and want to end up at x2 facing in v2, then the shortest path (assuming a finite turning radius, which realistically should be proportional to the square of the velocity) takes you along an arc of radius r1around m1, followed by a straight line segment and then another arc of radius ...


1

I would add some AI (artificial intelligence) checks. A first thing to do would be to check if the distance to travel, in comparison with the distance to the enemy makes sense to apply the Bezier curves. For example, you could make the weight (i.e.: distance from the end point to the control point of the Bezier curve) depend on the distance travelled and the ...


0

If the player is looking directly at the camera we can use the following idea to find the direction the player should walk, based on the position of the camera. We have two vectors C: (camera.Transform.Forward) the direction the camera is looking at and P (player.Transform.Forward) the direction the player is looking at. By computing the acos of the dot ...


0

Raven's answer, while correct, doesn't really explain the underlying concept you need to understand. Textures aren't technically applied to meshes directly; instead, Textures are assigned to Materials, and then Materials are assigned to Meshes. Thus you either need to change the texture assigned to the material that's assigned to the mesh, or (as in his ...


1

I would check your scale. Physics in Unity are designed to work at real life scales (1 unit = 1 meter) If you create a scene that is not to the correct scale, you are going to have a terrible time getting it to look correct. Example: Lets assume your ball is supposed to be a basketball. A standard basketball is 23cm (0.23m) If you build everything to ...


2

Your question is very unclear. You can use prefabs if you copy from them into your sprites instead of referencing. This way sprites you get will be independent from prefabs after creation, so you can change prefabs and sprites will remain as they were made.


3

With so many timers, you are better off with setting ExpirationTime for each of your events. When you need to start a "timer" set the events expiration time to "now" + "timer duration". Then add just one timer that will run e.g. each second and check all the "expiration times" and fire events when their time has come.


-1

I shall rephrase, the direction the player is facing is the forward direction, Therefor the camera should face forward (i.e the direction the player is facing), so the camera should be aimed at the player location always (unless you choose it to follow a different object like a vehicle) so there fore the camera facing point is player.location (This isn't ...


0

Anko was right with his comment. Physics.gravity is a static vector 3 variable that you can change in your code. http://docs.unity3d.com/ScriptReference/Physics-gravity.html You can modify gravity along with things like friction and drag to give desirable results.


2

Add a flag to determine if the player has been stopped. At that point, stop setting the players position to the camera's, and instead some other input. public float speed; public test testing; bool stopped = false; // Use this for initialization void Start () { speed = 10f; testing = Camera.main.GetComponent<test>(); } // Update is called ...


0

You can use GUILayout which is from before the 4.6 beta to accomplish this. I would create a new area in the top right corner, then have a flexible space inbetween the left bound and the last heart. You can create a new row by having a vertical area. This is how I'd make the hierarchy -BeginArea | -BeginVertical | | -BeginHorizontal | | | -FlexibleSpace | | ...


0

Just like with almost ANY unity3d package there is a file called read me.txt. This is where the general use and how to is explained. This file can be found after importing the package in the folder Assets/Highscore/readme. Pictures also seem to be included with this particular one Import the package Create database Create table in database (use ...


1

Don't directly translate the object in response to key presses. Instead, increase the speed in response to key presses, and then translate the object's position using that speed. That way the speed changes every frame. pseudocode: float speed = 0f; float maxSpeed = 20f; float accel = .2f; void Update() { if (Input.GetKey(KeyCode.I)) { speed += accel; ...


1

Lets see what you're trying to do : you're trying to check if 1 entity collides with N other entities, but I suppose those collide as well. Basically (if I understood you right) you`re trying to do N*N comparisons every frame, or even N. You should, first and foremost, switch your data structure. Use a quadtree, with that, you will have a complexity of ...


4

You should be using layers. That is you have a naked character sprite. On top of that you add layers for hair, armor, gear, weapons. Depending on your actual game, you might do that in generic form, or split in parts or even add skeletal system. For example in Diablo 2 character was split into parts that were combined: Here's another example of ...


2

Three vertices are easy. Just place them in the same location as the three vertices of the clicked face. For the rest of this answer, we'll call these vertices v1, v2, and v3. To position the 4th vertex, first take the cross product of v1 → v2 and v1→ v3. (If this returns a vector pointing backward, just swap v2 and v3.) vUp = normalize(cross(v2 - v1, v3 - ...


0

I read this and thought it would be a fun exercise this morning, so I decided to write this for fun. The implementation is pretty simple, keep adding lines at the end of each other until the last line is outside of the viewable area. The following code will draw a line infinitely going right. As an added optimization, the lines on the left side of the ...


0

You need to convert your cursor position into world position: Vector2 adjustedPosition = Vector2.Transform(touchCollection[0].Position, Matrix.Invert(camera.View)); Then your direction would be: direction = adjustedPosition - toolPos;


3

I did the following to achieve results: Added a Rigidbody2D to the player (deactivate Gravity). Added a 2D-Collider to the bomb. Added control and health script (basic stuff, just position updates). My health is just a public variable. Used the following code in playerPhysics.cs: void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.name == ...


1

My approach is similar to @Anko's, but based on the work by Millington and Funge from Artificial Intelligence for Games. This is what a Separation behavior would look like, but you need to take into consideration that this velocity should be computed with the agent's speed in its Update function. public Vector3 GetSeparationVel (float threshold, float ...


1

Turning on convex mesh fixed the problem. I have done it by script, because after importing object from blender there is no check box allownig to do this.


14

Give your agents a weak "electrostatic charge" to make them repel each other, along the lines of Coulomb's law. Assuming for simplicity that mobs should push each other away with equivalent strength, it should be enough to apply a force between every pair of mobs with a magnitude some_constant / distance^2, where some_constant is a configurable repulsion ...


8

Would this be a good place for inheritance? No, this is a good place for composition, see the Strategy pattern for more details. First of all, define an interface for your skills. Each character will have an instance of a class that implements that interface as a member. This ensures that you can switch between skills at runtime with ease. A simplistic ...


1

(coincidentally I just wrote about this topic for my book. That chapter should be released next week; here's a brief summary) There are two primary steps to what you're trying to do: 1) Determine which direction to face 2) Rotate the player to face that direction The first task is handled via transforming the direction vector from camera-space to ...


0

I had a very similar requirement for a game I'm working on. Here are some code snippets (although its in Swift and not C#) with some explanations: Input state: before filling in gaps wave 0 = [1.0, 0.0, 0.0, 0.0] wave 1 = wave 2 = wave 3 = wave 4 = wave 5 = [0.5, 0.5, 0.0, 0.0] wave 6 = wave 7 = [0.3, 0.3, 0.3, 0.0] wave 8 = wave 9 = [0.75, 0.0, 0.0, ...


0

Code provided by Katherine Rix: // Position camera to follow behind player's head. private void Follow(){ // orientation as an angle when projected onto the XZ plane // this functionality is modularise into a separate method because // I use it elsewhere float playerAngle = AngleOnXZPlane (player); float cameraAngle = AngleOnXZPlane ...


0

First of all you need to interpolate Enemy ratios for level you need. This is quite trivial - for each enemy type, interpolate between ratios of known levels. Knowing exact ratios for the level (e.g. (0.45, 0.45, 0.1)), there are several ways, each good for specific usage scenarios: Batch Add N items for Enemy0, where N = RoundUp(Enemy0_Ratio * ...


1

Since Unity 4.2 there is a class called Androidjavaproxy which can do exactly what you are looking for. This class can implements any Java interface in Unity.


0

This problem is a bit complex. There are multiple approaches you can take. None of them are "wrong", per se, but each one is better suited for a certain number of enemies/level layout/(etc.). Regardless of the approach you take I find it very useful to extend Unity's editor for cases like this. The approach I'd use for a simpler tower defense game would be ...


1

You've got quite a few problems here. First, the DeclarationUsage enumeration maps to D3DDECLUSAGE under the hood; these values are not flags, so or'ing them together doesn't make sense. When you create the vertex element array for a vertex declaration, each vertex attribute (position, color, et cetera) must be its own element. Thus, you should initialize ...



Top 50 recent answers are included