Tag Info

New answers tagged

0

I really doubt that the depth Buffer is inaccurate, the issue is much more likely the the boxes are further than the far pane or your shader is calculating something incorrectly. Anyways XNA has built in functionality for generating a Depth Texture. RenderTarget2D shadowRenderTarget; shadowRenderTarget = new RenderTarget2D(GraphicsDevice, ...


1

Unity does not have this kind of "direct mode" rendering, you won't be calling Draw in any update loops for Unity. In Unity you need to create a game object, then attach scripts to that game object. Those scripts will control how the object behaves, if and how it's displayed on screen, if it's part of the physics system etc. To create a new sprite to draw ...


0

Does normalizing the vectors make a difference? @Jon: Good catch, normalizing "directionVector" seems to make the math work out (transform.forward is already normalized). So if you make this an answer I'll mark it as correct. If possible, could you elaborate on how normalizing the vector makes the math work out? I'm familiar with the concept of ...


1

if (Math.abs( angle) < mindelta ) transform.LookAt (currCustom); I think it depends on floating point math errors, I suggest to define a min angle inside wich, the turret doesn't move


2

OnApplicationPause(bool state) is called when the user pauses and unpauses the game, normally by hitting the Pause button found in your game (which you need to implement the functionality for - by setting Time.timeScale = 0). Sometimes it's called when the application is put in (or comes back from) the background too (user hits Home button for example). But ...


0

You can create a 2D rotation from a 3D one by just ignoring an axis (usually Z). Quaternion 3dRotation = Quaternion.Euler(myRotation); Quaternion 2dRotation = Quaternion(3dRotation.x, 3dRotation.y, 0.0f, 3dRotation.w); Using this method you can modify your rotation to ignore one or two axis. Or, you could use the same aproach when working with the ...


0

Assuming "LoadContent" gets called once at startup and "Update" gets called every frame, your issue is probably because the ball's X and Y coordinate got set to 5 every frame in the update method, therefore, it wouldn't be moving around freely... If it gets called once in the LoadContent method then it does not continually update the X and Y position to be ...


1

When you have a vector from your spaceship to the earth you can just calculate the projection of the vector onto your 'camera plane'. You can normalize this vector and you have the direction the arrow should point to. So you can use what you already have, rotate a vector and project it onto the 'camera plane'.


2

LookAt definition: public void LookAt(Transform target, Vector3 worldUp = Vector3.up); The default orientation, Vector3.up, it's not correct in your case (that's why the bullet is oriented upwards). Use: transform.LookAt(go.transform.position, Vector3.right);


0

You're using Update incorrectly. Update is called automatically every frame by Unity, on every component attached to every object (you can see this with the default comment that still exists in your code // Update is called once per frame). You don't need to call Update manually. I see you're aware of having conditionals in the Update loop. What's wrong ...


0

You could use a static constuctor Static myEditor(){ myObj = new MyObject(); } This will run the first time you access the class


0

You could have a velocity like new Vector2 = (0,5) (notice that the vector is pointing down just like gravity does) and apply it to your player in every frame: playerPosition += Velocity. Then you can check IsKeyDown(Keys.Up) and if it is true, then you apply the opposite velocity new Vector2 = (0,-5) (which is pointing up). A better way of applying ...


1

The control variable is a static variable. The code you're looking at is for ensuring there's always a GameControl object in the world, and only one. The first time a GameControl object is loaded, control is set. If a GameControl is ever attempted to be loaded again, it will not match the already loaded control object and will be destroyed.


1

This is the implementation of a very simple version of a programming pattern called Singleton. For more context, see Unity Singleton Pattern. The basic idea is, the designer wants that there should only be one instance of the GameControl object. Therefore, before everything else (in Awake() function), the designer checks if the object is initialized or not. ...


0

I would create a separate InputMapping class that simply correlates different Unity input names with my own input names. Then other parts of the game (eg. a keyboard settings popup) can change these mappings (eg. what InputMapping.Forward maps to). Now change the FPS movement script to use the settings from InputMapping instead of referring to Unity inputs ...


0

I solve the second problem. It was in front of me all the time. As I said, I was using this code as example. What this awesome answer doesn't explain you is that once you compile the code, if you select the sprite back on hierchy you'll notice two variables available, corresponding to the one you declare back in the code. My BIG mistake was not ...


0

create the low-resolution elevation map with the algorithm you used first scale it up using linear interpolation add another round of perlin noise to the upscaled elevation map, this time with the higher resolution but smaller height scale. This will add more detail to your landscape.


0

This isn't really so much of a MonoGame issue as much as it is a .NET issue. The XML files are unimportant and can safely be deleted as they only contain the documentation for the matching DLL files. I'm not sure if there is any kind of legal requirement for you to keep them around but I seriously doubt it. I am not a lawyer. Moving the DLL files though ...


1

I do this in my game by generating a distance field to a set of line segments, and using that as an additional mask on top of the radial one. Here's how its done: Generate N pairs of random points and connect them together as line segments. For each pixel in the mask, determine the distance to every line segment. Take the min over all segments, called d*. ...


0

XNA has 3 sampling methods built in. Point Linear Anisotropic There are two main concepts here the source image and the destination on the screen. Sampling is the algorithm that calculates the pixel colors for the destination by sampling the source image. If you use a destination rectangle that is the same size as the source and has whole number ...


0

I made some changes for your CombineTextures method, public static Texture2D CombineTexture(GameObject obj, Texture2D background, Texture2D TodrawLogo) { int width = TodrawLogo.width; int height = TodrawLogo.height; int backWidth = background.width; int backHeight = background.height; // bottom right corner int startX = backWidth - ...


0

I don't what your code architecture looks like, but you will have to make this check at some point. The simplest way to do this, imho, is to be sure that the local player only receive his own events, so, be sure to make him register to only his event. You say that, at click, you know who has clicked. Why don't you just send the event to this specific ...


0

I think the orthographic size of your camera should depend on the size of your sprites (and possibly on the aspect ratio of the screen), but not on the size of the screen, so that you don't need to apply any scaling to your sprites. As a reminder, the orthographic size of the camera is the half-height of the area (in Unity world) which will be rendered on ...


1

So long as the SpriteSortMode is SpriteSortMode.Immediate you can make alterations to graphics device in between draw calls which allows you to change the ScissorRectangle, RasterizerState, SamplerStates, ect... Of course you lose the performance optimization from the batching; however, it is sometimes worth it if the alternative is creating many begin/end ...


1

If your testTextureArray[i] is pointing to the same texture, you should have the same performance, but if not, then you are just hitting a design restriction of SpriteBatch. Most implems of SpriteBatch I'm aware of (at least, XNA, SharpDX, Paradox, DirectXTk... though, don't know for sure about MonoGame...) are trying to batch draws with the same ...


0

You can easily achieve that effect by using a Second Camera. Assuming that your Main Camera has Depth -1, add a second camera with Depth 0. Doing this will make the Second Camera render after the first. You can then apply a specific layer Layer to your watermark object and then configure your Second Camera (Culling Mask property) to render only the ...


0

Set the mass of your projectiles to be very low, and the mass of your characters to be higher until they are no longer affected by the collision of the projectile (mass is a variable on rigidbody component). The reason your rigidbody's push each other away is because this is what physical objects do in real life and rigidbody simulates this as accurately as ...


0

To get continuous updates without degrading the UI performance, you'll need the following trick to hook into the windows message queue: public static class NativeMethods { [StructLayout(LayoutKind.Sequential)] public struct Message { public IntPtr hWnd; public UInt32 msg; public IntPtr wParam; public IntPtr ...


1

You are right that the correct function is Unproject. Try this: Vector3 modelPosition = graphics.GraphicsDevice.Viewport.Unproject( new Vector3(100.0f, 100.0f, 0.01f), // Note the 0.01f! effect.Projection, effect.View, Matrix.Identity); The 0.01f means you want a point that is 1% of the way between your near and far clip planes (the ...


0

Make sure your build target is set correctly. If that is, then attach a debugger to your code. Wrap your sound code in an exception handler and examine the conditions that led to the exception being thrown. With this information, you can either code to avoid those conditions, or depending on the conditions, modify MonoGame to ignore the exception.


1

Yes, you can configure your Lights to affect only certain objects, by using Layers. Assign your objects to a specific Layer (you can use an existing layer or define your custom one). Then, in Inspector pane, use Light's Culling Mask setting to set which Layers you want it to affect.


0

In your comment you mentioned that you are setting the game objects positions instead of relying on forces or velocity. If I had to take a guess, the problem you are facing is having two rigidbodies colliding together, which in turn is affecting other rigid bodies. You have two options in this case Remove the rigidbodies altogether. If you are not using ...


1

You may want to look into this and this. Unity makes it really easy. The scripting reference is your best friend. Something like the following: if (Input.GetKeyDown(KeyCode.LeftArrow)) transform.rotation = Quaternion.Euler(0, 30, 0); else if (Input.GetKeyUp(KeyCode.LeftArrow)) transform.rotation = Quaternion.identity;


2

This question seems to be an X/Y problem. I think what you are really asking "how do I rotate a set of triangles?" You've settled on a very slow, very wrong solution to this problem. You should never be directly modifying vertex data on the CPU, unless you absolutely have to. I think your answer boils down to replacing: ...


0

Depending on the game's field of play's size, divide the area you wish to populate with planets into a grid where each square can contain a planet in it's entirety. Now Randomly decide if there is a planet in each square of the grid, by randomizing a number. NUMBER_OF_SQUARES = width * height; NUMBER_OF_PLANETS = 28; planetsLeft = NUMBER_OF_PLANETS; while ...


0

Since your plane is perpendicular, you wouldn't use the normals. Just like your second drawing in your album: Just ignore the Y and Z axis, of the terrain. For each point you want to match on the terrain, take the X axis value, and match that value on your perpendicular plane. For example, if the point is at (1,3,0), just take the point (1,planeTop,0) on ...


2

EDIT: I see your updates now, I'd suggest you try implementing something such as my first suggestion. Since you didn't post any of your code, I'm going to have to guess at how you're doing the collisions. Are you using a single pixel collision check between the player and the enemy with the wall or other related sprites around it? If so, there are probably ...


0

Okay, I'm not going through debugging your code because I think there is an easier way. Rather than checking for per pixel or rectangle collision, why not maintain a list of Vector3s and a list of floats? Populate the list of Vector3s with positions and the list of floats with the radius of the planets. private bool AddPlanetIfNoCollision(Vector3 position, ...


0

In the similar scenario i've used polling model (updating input every frame), composite pattern (which you already implemented) and rectangle hit detection. Every frame visual tree root (GUIManager, in my case) polls its children, calling the Update with the mouse coordinates, until one of them reports that the mouse is inside of it. This control will also ...


0

OnTriggerEnter2D is supposed to have a Collider2D parameter. As yours have none the method signature is different and that's probably why it's never called when a collision occurs. Also as explained in the documentation I would strongly suggest to use StartCoroutine in it's method parameter form instead of using it with a string parameter. I hope it ...


1

Rotate will rotate it once by the amount specified. You must rotate it yourself every frame. public float rotationSpeed = 50f; public GameObject target; private bool rotate = false; void OnMouseDown() { rotate = !rotate; //this line toggles the bool "rotate" every time the object is clicked } void Update() { if(rotate) { ...


2

Don't Rotate() in OnMouseDown(). Instead, have OnMouseDown() set an isRotating boolean value and then Rotate() in Update(). Something like: bool isRotating; void Update() { if (isRotating) { target.transform.Rotate(etc); } } void OnMouseDown() { isRotating != isRotating; }


0

For the gameObject to always stay in the corner set it's position to camera.ScreenToWorldPoint(new Vector3(0, 0, -camera.gameobject.transform.position.z)) - new Vector3(yourObjectsizeX / 2, yourObjectsizeY / 2,0) [this to make sure the whole button is visible] Regarding the scaling, I did a while back such a scale to the background by defining the width and ...


2

Use the unit test framework 'Unit Test Tools' provided by Unity. You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests? Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use ...


2

To check your collision you simply take the players position and divide it with the size of each map element to get the index of where the player is in the map, then check for collision surrounding that. The player is 48x32 and the map is 16x16 so (48,32) / (16,16) = (3,2). But since the player can move smoothly you need to add one more coordinate to each ...


1

For the question of how to deserialize an xml file in c#, this question on stack overflow explains it pretty well: How to Deserialize XML document The gist of it is, you need to create a class for each type you are going to represent in the xml files, in the example you gave it would be event, item, item_modify and possibly battle, and define for each ...


0

//Load the texture RenderLoop.Run(form, () => { context.ClearRenderTargetView(renderView, Color.Aqua); //Use SpriteBatch to draw it swapChain.Present(0, PresentFlags.None); }); or //Load the texture //Create and fill buffer for quad RenderLoop.Run(form, () => { context.ClearRenderTargetView(renderView, Color.Aqua); //draw the ...


0

This function takes in mouse coordinates and picks the model from the 3d scene by shooting a ray through it. Btw the screen size in world coordinates is 2x2 stretching from -1 to +1 on both the x and y axis. The screen size in pixels would be mClientWidth and mClientHeight. You'll see both those in "Compute picking ray in view space" void Pick(int sx, int ...



Top 50 recent answers are included