Tag Info

New answers tagged

2

It looks like your code to mirror the bullet's angle just flips the sign of the angle. This works great for reflecting an angle about the x-axis. 45 degrees becomes -45 degrees, etc. Now imagine reflecting off a wall that itself has an angle of 90 degrees. In this case, 85 degrees is reflected to 95 degrees; 45 degrees becomes 135 degrees, etc. Basically ...


2

you are in a voxel engine which means that each box should have a discrete x, y and z coordinate thus: if you have a box at index (x, y, z) then you can get all neighbouring boxes by getting the boxes at index (x, y +/- 1, z), (x +/- 1, y, z) and (x, y, z +/- 1) edit: after some more info... just detect the collisions for a line between the center of the ...


0

What you probably want to do is create wrapper around SpriteBatch or create extension methods for SpriteBatch that apply the desired per-sprite inversion to each Draw call. Then you could just do: spriteBatch.DrawWorldSprite(texture, position, color); (You could even create an overload with a scaling parameter, that does appropriate multiplication so you ...


1

This should do the job, it will follow the player and face the player as well. Hope this helped. using UnityEngine; using System.Collections; public class ChasePlayerAI : MonoBehaviour { public Transform target;//set target from inspector instead of looking in Update public float speed = 3f; void Update() { //rotate to look at the player ...


0

To #2: yes, you are doing it wrong. You are trying to change the framework's 2d coordinate system, with its origin at top left (this follows texture coordinates convention in directX). You are allowed to make that change; the trade-off is that you have to do it all the time, with every draw. Since that's what you seem to dislike, you might consider the ...


0

If your maps are small, which the one above seems so, using a list of blockCollidable = true items. Then when the character is moving have an foreach(Block currentBlock in Collidables) { if (player.X + tileWidth > currentBlock.X && player.X < currentBlock.X + tileWidth) { if (player.Y...) { //Collision Code } } } ...


1

If by your question you mean that a ship has to be hit twice (or multiple times) before exploding, simply give your ships hit points. Whenever a bullet collides, remove the bullet and decrement the hit point value. When the hit points reach zero (or less), blow up the ship. If, however, you mean that a ship explodes if, and only if two bullets collide with ...


1

As far as I know, most programs will separate geometry for rendering from geometry for physics. (This is because rendered models can be incredibly detailed, and hit testing against each polygon will take way longer than say, a couple quadtree intersection tests.) If you're using a small number of simple rectangles, you could simply test each rectangle ...


5

No, there's no way to do this. What you're looking for is a container, that holds references to rectangles that are insides its bounds. This isn't an easy thing to do when you really think about it. There is no way for the rectangle object to know any other rectangle object exists, let alone know if one is inside of it or not. However, there is a few data ...


1

What you generally see in these games are repeated parts of the level. You can create "chunks" which contain a piece of road and the related props (trees, road markers, signs, etc). You can create many different of these chunks, just make sure that the end of a chunk matches the next one. Then, when your car is moving forward (or the chunks move backwards ...


-1

I found myself that it is a bug of OpenGL version of Monogame. Just create DirectX version and it should work. Edit1: Issue has been send to the tracker. https://monogame.codeplex.com/workitem/7812


4

How install XNA 4.0 on Visual Studio 2013 Download XNA 4.0 Refresh (Visual Studio 2013) Unzip archive Install DirectX from the archive Install Xna Framework 4.0 Redistribution from the archive Install Xna Game Studio 4.0 Platform Tools from the archive Install Xna Game Studio 4.0 Shared from the archive Install XNA Game Studio 4.0.vsix from the archive


2

The error you are getting appears to explain both the problem and the solution: Cannot change read-only RasterizerState. State objects become read-only the first time they are bound to a GraphicsDevice. To change property values, create a new RasterizerState instance. You can't change rasterizer state objects once you have bound them to a graphics ...


1

I created a helper class that takes in the following arguments and lets you align or center the text within a Rectangle both vertically and horizontaly. Passing in neither enum results in the same behavior as the default spritebatch function. The options for the emuns are. public enum TextHorizontal { LeftAligned, CenterAligned, RightAligned } public enum ...


0

There are several solution to your problem. The first solution i can think of is instead of using one rectangle you can use 4, or even 9+ if you need more detail. Put a top-left, top-right, bottom-left, bottom-right rectangle within your main rectangle. When you have the collision you currently have you can check on the more detailed rectangles and see where ...


0

Lets say you have a player and a bunch of tiles. Then you can set a category on each. This is done by a bit-value. A bit contains 0000.0000 places to be assigned. Best thing you can do is use values like 2, 4, 8, 16, 32, 64. In between values may cause collision within the bit and cause it to drop a category or a mask. So first create to categories. ...


0

I would do something like this: int pixelPerFPS; // pixel per FPS void move(int x, int y); void update(int time) { character.currentX += (character.goalX - character.currentX) / abs(character.goalX - character.currentX) * pixelPerFPS; character.currentY += (character.goalY - character.currentY) / abs(character.goalY - character.currentY) * ...


1

It's been a while since I've touched farseer, but if I remember right, it shares a very similar API to Box2d. So you should have something like: Fixture.filter.categorybits; Fixture.filter.maskbits; So let's say your blue box is setup: Fixture.filter.categorybits = 0x0001; Fixture.filter.maskbits = 0x003; Your black box is setup: ...


1

If you are talking about move horizontally and vertically at a same time, the problem is not here. You are doing fine. Maybe problem belong to input module. About A*, it's a path finding algorithm, it return series of point present the path you ask for. Movement is another problem, don't stick it with A*. The easiest way to implement moving system are ...


4

Loading up DirectX (via SharpDX or XNA) to do the conversion is probably overkill. Why not simply decode the format on the CPU? It's simple enough. There is a DXT decoder in MonoGame you might be able to borrow. (In case the file changes, the latest revision at time of writing is here.) BC3_UNORM is equivalent to DXT5, which that will happily decode. ...


1

You really just need a 2D camera and I'm sure you will want it locked onto a sprite on your screen, which is what you mean by smooth scrolling. If you just want a working implementation, you can find one over here working at StackOverflow. With that out of the way, I'm going to explain a bit how it works on a deeper level. A matrix is used to perform ...


3

The draw order often implied by tutorials, where you do something like this: for each object: for each pass: apply pass state draw object is actually backwards from how it makes sense to do it in a "real game" context. Rather, you'd be more likely to do something like: for each pass: apply pass state for each object (grouped ...


0

You were right, Martin. The SurfaceFormat settings were off in the 2d texture. But for anyone wondering, here is a quick map how GetData/SetData works for the default GetData(data)/SetData(data): So basically your layers should be located BELOW your first picture in the 2d atlass to put them into the 3d texture seamlessly.


0

I am not sure if you are trying to draw sprites (images) or points, but for sprites you should use the spriteBatch.Draw(,,); function, where the first parameter points to a Texture2D object, the second to a Vector2 and the third to a color for further effects. The color can be taken from the Colors item, which is built into the XNA, normally you would put ...


0

I have the same setup like you. Considering you have your Monogame Windows Project (or whatever plattform you are targeting) then simply follow: Add new project --> MonoGame --> Monogame Content Project --> Rename it whatever you like to Then you can add your content to the content project. Build it (this should create xnb files). Add reference to ...


-1

I had the same problem and used the following pixel collission which I found on the net (sorry i dont know who made that, sorry for no credits :D) and modified it a little. The 2 Gameobjects checking first, whether they are allowed to collide and then it itereates about the overlaying pixels of object something and target. private bool ...


0

Alright, so an easyish change to your algorithm will make it both neater and probably work better: You use ShadowChecker as Character rect that you move downwards. Instead, expand it's height to either infinity or the bottom of the screen (FloorRect.Y). After expanding it, loop through the platforms: float currentHighestY = ShadowChecker.Y; ...


0

Bodies in Farseer have no "shape" of their own. The Body defines the position, velocity, mass, etc (basically a point-mass). Fixtures give that body a "shape" that can collide with things. You can get the AABB (axis-aligned bounding-box) of a Fixture with Fixture.Shape.ComputeAABB(...). Don't use Fixture.GetAABB, which is a "loose" AABB used by Farseer for ...


1

Get the list of contacts for each body by walking the contact list (a linked list). Note that a Contact might not actually be touching, it might almost be touching. A contact can also be disabled. ContactEdge ce = body.ContactList; while(ce != null) { Contact contact = ce.Contact; if(contact.IsTouching() && contact.Enabled) { /* ...


5

Scenario It seems your pathfinding and collision detection have different ideas of what's OK, when it comes to walking around corners. Say your pathfinding plans out this path (brown squares are walls, yellows are empty space, green is an enemy character, arrows are the planned path): The enemy character then moves directly toward each point from the ...


-2

Try this approach: Spawn a shadow object on the X and Y position of the player, then apply a very strong gravity force, and check for collisions (just like you do with the real player) Then on the next frame update the coordinates of the shadow object with the new X and Y cooordinates of the player (I.E. place it on the same coordinates of the player) Then ...


1

It may not be the best answer but, Make an object called ShadowChecker that constantly draws a rectangle/line below the player. Use collision detection to adjust the height of the rectangle/line until it's not colliding with any object besides the player AND there is a platform just below the collision box. Then check the Y position just below the ...


25

I would recommend checking out the explosion iforce2d page. It does a great job going over the various ways of handling explosions with the performance vs. accuracy tradeoffs. It goes over 3 methods which I will summarize here. So this is simply me summarizing information I found while researching and none of it is my own work. Also you want to apply ...


2

Select all the objects within the bomb's radius of influence. For each object Use the object position and the center of the explosion to calculate the vector of the impulse. Something like normalize(object - center). Use the distance from the center of the bomb to the object to calculate the magnitude of the impulse. Something like (object - center).length ...


0

Normally XNA only works in VS2010, but you've already linked the solution to that problem. Only certain project types can have content project references. So what you need to do is create an empty "XNA Game Library" project - just for building the content project. Then either reference that empty project or manually modify the underlying .csproj file (or ...


8

Draw a shadow sprite like you draw your character before the character (to make it appear behind him). Make sure its X position is updated according to the character, but the Y position stays on the tile. You have got a shadow.


1

You are checking each object against each collision tile, even when those are too far away to have a chance to affect it. That's inefficient, because the computational cost increases quadratical with the amount of objects. Divide your map into zones and keep track of which zones each mobile object touches. Then only check for collisions inside each zone. ...



Top 50 recent answers are included