Tag Info

New answers tagged

0

You cited games like "Jetpack Joyride" and "Geometry Dash" so I understand you are working on a 2D game with side scrolling view. I assume the Y is up and X is right. In Jetpack joyride: - the camera is fixed - the player only moves along Y-Axis - you move transform the level and background to simulate that the player is moving, so the player speed is ...


1

Make the camera object a child of the object that's moving. This is super easy and doesn't take any additional scripts. Make a script for the camera that will update its position based on a target object: Example: public GameObject targetl; public float xOffset = 0; public float yOffset = 0; public float zOffset = 0; void LateUpdate() { ...


0

You should probably let player use their own tool and allow them to mod/upload an icon for this purpose into the game. Drawing it in game, is a matter of tracking the mouse position and clicks, designing the drawing tools gui and simply adding and removing pixels at position (x, y). It is not complicated but sounds like a waste of time if you could allow ...


0

When you create a rotation matrix or quaternion from an angle, you are actually taking the sine and cosine of a numeric value in radians. Your value in degrees is being converted to radians, so 90 degrees becomes π/4. π is not something that can be represented accurately in floating point. This is where the accuracy loss is coming from. If you take the ...


1

Floating point math is not perfect. You're trying to compress an infinite set (all real numbers) into an extremely finite space (32 bits). Consequently, not every number can be accurately represented, and some numbers will suffer from rounding error. Basically, as you do increasingly more math on some particular value, you increase the chance(*) that the ...


0

Eventually found out. Turns out it was very basic. This is probably not an efficient way, but it serves the purpose. The problem was the yield return statement returns a value immediately without waiting for confirmation from the master device. To solve this, take the value and check if it is indeed the value we require, if not call the coroutine again with ...


1

This is an interesting problem. I can think of two mechanical (brute-force-ish) approximate approaches. My math-fu is not strong enough to opine if an analytic solution is practical here. I hope there is such an approach! But here’s my “just get it done” suggestions. By Gridded Area, approximate We only care about the blue area. Represent that to the ...


0

Try to get the sphere equations with respect to world space for each sphere like a sphere with radius r and centre (a,b,c) in WorldSpace Coordinates will be represented by the equation (x - a)^2 + (y - b)^2 + (z - c)^2 = r^2 then find the common portions and subtract the equations to get the blue part and any solution of the remaining equation will be a ...


0

Found the issue. You have to use tex2.Apply(); For the SetPixel() changes to take effect.


1

Try adjusting the Max Angular Velocity in the Physics Manager. You can access the Physics Manager by selecting Edit->Project Settings->Physics from the menu bar. The default value is 7. Maybe try a value around 100. That seemed to work well for me. You can override the Project Settings value of Max Angular Velocity for any Rigidbody by scripting ...


1

Trigger an event, or just call the change method when you change the type of terrain object. Pull you color switching code out of start and put it in its own method. Then, have start call the SetColor method, and have your code that switches terrain types also call SetColor whenever the type changes. It's not something that needs to be done every frame, ...


3

The reason you wouldn't put the initialize logic in the constructor is because Initialize is the first point where you can be sure that GraphicsDevice is set up. Recall that, while your constructor for your Game-derived class may create GraphicsDeviceManager, the graphics device itself is only created when Game.Run() is called (an instance method, so it ...


0

XNA implicitly supports what you're doing via it's GameComponent classes. Taking advantage of these will solve your issue, but then you're shoehorned into using their design approach. The Game class -- which your main object loop inherits from -- has a handy property called Content, which is a reference to a ContentManager instance. This is all set up for ...


1

Here is my implementation of Zehelvion's suggestion. An octree wasn't necessary but his suggestion helped to formulate the following method: private static int[] GenerateAdjacency(Vector3[] positions, List<int> positionIndices) { // faces within mesh int ncFaces = positionIndices.Count / 3; // vertex count ...


2

Disclaimer: this is not the academic approach to reduce complexity but it will work in this case. Build a 3d uniform grid or an Octree (depending on data distribution) of Edge arrays around the scene. Add each edge to the appropriate slot (based on the edge's center) in the grid / Octree. If the edge's center is epsilon away from the inner border of the ...


0

I've found a solution: public void Draw(SpriteBatch spriteBatch) { //Interpreting tiles as bounds //Sub-ing and add-ing 128 just to get more tiles than visible, //so the world feels like more alive // 16 - is tile size // 128 / 16 = 8 more tiles int startX = (va.area.Left - 128) / 16; int endX = ...


0

Looking over the code you should be able to : switch (CurrentGameState) { case gameState.mainMenu: MediaPlayer.Stop(); MediaPlayer.Play(song); break; case gameState.gamePlaying: MediaPlayer.Stop(); MediaPlayer.Play(song2); break; } I wasn't sure if calling .Stop() without music playing ...


2

In Unity you can load any text file with Resources.Load() like this: string text = (Resources.Load("NameOfTextAsset") as TextAsset).text; After that you can use any standard C# method to split the string to parts, and Convert.ToInt32() to parse the integer from the splitted up string. foreach(string part in text.Split(' ')) { int number = ...


1

To answer your question simply: Get list of all the RenderComponents, and a list of all the Movement Components. We assume each component has a field which gives the entity is is a part of. Sort them by entity ID. Obviously, if you keep these lists sorted in the systems themselves, then this is very inexpensive (maintaining the sorting is cheap). ...


1

You could store components two-dimensionally in a list of lists: List<List<PslComponent>> _componentsByType; You use the component type ID as the index into the outer list... List<PslComponent> componentByEntity = _componentsByType[componentTypeId]; ...and then use the entity ID to look up the component of that type on that entity (or ...


0

Don't iterate over all entities and see if they have an interesting components - only iterate over entities that have your interesting component attached. One way is to use a nested dictionary of the following type (no particular language here): components: Dictionary<TypeIdentifier, Dictionary<Int, Component>> This lets you look up the ...


0

So you are on the right track but using not understanding what some of the parts of your code do. GameTime.TotalGameTime Property Game time since the start of the game. GameTime.ElapsedGameTime Elapsed game time since the last update. MiningElapsed is currently set to the number of seconds since your game started. As a result its always going to ...


1

The problem with arrays is that they can not resize dynamically. When you exceed the initial capacity, you need to allocate a new array and copy the whole array over. When you want to remove an entry in the middle, you need to move all entries after it down by one. These are both very expensive operations when your array is large. The List class is an ...


1

A health/damage mining system would be much more flexible and should be easier to implement than a fixed, time-based system. Basically, assign each block a health value, and your pickaxe a "mining damage" value, and whenever the pick strikes the block, you subtract its damage from the health of the block. When the block's health goes to zero or below, the ...


1

C# Version. using System.IO; void readTextFile(string file_path) { StreamReader inp_stm = new StreamReader(file_path); while(!inp_stm.EndOfStream) { string inp_ln = stm.ReadLine( ); // Do Something with the input. } inp_stm.Close( ); }


2

There's class named TextAssets which is used for text file read. http://docs.unity3d.com/Manual/class-TextAsset.html here you can find the supported file format. so if u want to read read the text file, script would be like this: class YourClassName : MonoBehaviour{ public TextAsset textFile; // drop your file here in inspector void Start(){ ...


0

Forget trigonometry. Use vector math. Think of it as solving an equation: you want the position of the platform and the position of the enemy to be the same at some point in the future. So you write the equations of motion for both, and solve for the velocity of the enemy: platform_x = platform_x0 + vel_platform0 * t + accel_platform * t^2 / 2 enemy_x = ...


4

I found I had to do the following to set the FPS limit free. In your Game class, do the following: graphics = new GraphicsDeviceManager(this); // I have this stored as a member variable graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false; Note that an unlimited FPS can cause unpredictability in physic engines, and network games. A ...


1

The FPS is capped at 60 because of the default value of true on Game.IsFixedTimeStep. If you set this value to false it should allow your FPS to go to whatever you need it to. Game.IsFixedTimeStep on MSDN


4

There are many different variables that come into play regarding this. If two faces are next to each other that use different textures, light levels, colors, etc.. you more than likely won't be able to join them together anyhow (nearly anything's possible with enough work, but it'd probably be FAR too much work). If, however, you have a lot of cube faces ...


0

I have figured it out. Turns out, my logic was correct, however the imported mesh had it's normals messed up for whatever reason. Maybe I used incorrect settings when exporting FBX file from Max. I have calculated my own normals so now everything is correct. Triangle temp = new Triangle(); temp.Vertices[0] = ...


0

I have managed to get my application working with the first approach I was attempting to use. It appears that the way I am disposing of the GameScene is the cause of the issue. It seems as though it is also disposing of the SceneManager functionality which the GameScene is derived from as I noticed that none of my update and draw calls in both SceneManager ...


6

When you have a 3-dimensional world and you say you have 7 million tiles, I would assume that your game world is a cube of roughly 200x200x200 tiles. Instead of storing this in a hash table (Dictionary) you could also store it in a three-dimensional array. Arrays have much less overhead and much more predictable performance characteristics than hash tables. ...


3

Try changing your GetHashCode to something that better distributes the values to reduce the number of collisions in the dictionary. If your hash code is bad you're going to get the performance of a list rather than a hash-set. To show this consider a GetHashCode method that always returns 0 for any object. Trying to put that into a Dictionary will force ...


-1

Ricket answer is pretty full, but I want to share this link with you: http://www.redblobgames.com/grids/hexagons/ In this article you may see all what you may need in one place with interactive examples (examples in pseudo-code)


1

http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html Have a look at lerp. You'll be able to move to a position over time like this: transform.position = Vector3.Lerp( start, end, currentTime / totalTime ); Where start is the initial position of the object you are moving and end is the place you want to be once currentTime = totalTime. In your case, ...


1

You want to get real familiar with a handy-dandy 3D math operation called Dot Product. Pretty much all 3D graphics libraries include this 3D math function; for example http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector3.dot.aspx The dot product can be used for a number of things, but every use boils down to: when you take the dot product ...


4

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...


2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...


0

OK, I'm assuming that you're creating your random grid inside of a two dimensional array. int[,] grid = new int[5, 5]; int lastVal = 0; Random r = new Random(); for (int i = 0; i < 5; i++) { int startCol = r.Next(0, 5); for (int j = 0; j < 5; j++) //-1 indicates that the node is empty grid[i, j] = j >= startCol ? lastVal++ ...


1

public static Texture2D ConvertToTexture(System.Drawing.Bitmap b, GraphicsDevice graphicsDevice) { Texture2D tx = null; using (MemoryStream s = new MemoryStream()) { b.Save(s, System.Drawing.Imaging.ImageFormat.Png); s.Seek(0, SeekOrigin.Begin); tx = Texture2D.FromStream(graphicsDevice, s); ...


1

This code is working fine for me to read the content in the text file import System.IO; var filename="data.txt"; function Start () { var sourse=new StreamReader(Application.dataPath+"/" + filename); var fileContents=sourse.ReadToEnd(); sourse.Close(); var lines=fileContents.Split("\n"[0]); for(line in lines) { print(line); ...


1

You can do this in the same way you would in .NET string word = File.ReadAllText(txtFilePath); This code snippet can be used in any location you wish then.


0

I've already got a pretty reasonable answer to this over here, with some video examples. The short version is: You cannot reasonably use rigid body physics to simulate biped locomotion in the kind of responsive way you'd want for a platformer. You have to do something else.


0

I managed to find out what my problem was. The "smooth" keyword. Vertex shader: ... in float in_fl; flat out int FL; void main(void) { FL = int(in_fl); ... Fragment shader: ... flat in int FL; ... So now I have a red, a blue and a green square, as I wanted. Anyway thanks for any help.


5

First of all please read Array versus List: When to use which? for coverage of this issue from a general perspective. Now to focus on your case, I would recommend a list if: You don't know how many enemies you will have in advance (and don't want to worry about handling resizing) You would like to remove enemies from the middle (and don't want to worry ...


1

The easiest thing would be to create a gradient in Photoshop/Paint.NET/GIMP/whatever you use and blend that with your tile(s). If you want a more procedural approach, then take a look at Color.Lerp. A gradient with that method is simple. The first color parameter is the light shade, the second is the final dark shade and the progress is the row/column of ...


0

Fixing the issue was easier than expected public override void Update(GameTime gameTime) { graphics.ApplyChanges(); } It doesn't seem to impact framerate in any way (still getting 120)


2

SharpDX is a DirectX wrapper, not an XNA one. XNA's GetData methods are higher-level abstractions on top of the underlying DirectX functionality. If you're using the D3D9 interface, you probably want a variant of LockRectangle. If you're using D3D11 you probably want some variant of MapSubresource (or the similar method for D3D10). Note that in D3D9 the ...


1

It seems I have managed to resolve the issue by using the overloaded Texture2D.GetData (int level, Rectangle? rect, T[] data, int startIndex, int elementCount) method. Texture2D texture = level.Tiles[x, y].Texture; Rectangle source = level.Tiles[x, y].Source; Color[] colorData = new Color[source.Width * source.Height]; texture.GetData(0, source, colorData, ...



Top 50 recent answers are included