Tag Info

Hot answers tagged

28

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


17

I've never worked with XNA before and i think it will appear better solutions then mine. But a workaround that might work is that you could put a invisible object on the extremes of the cliffs and the monster could check for collision with those object. If it collides, then changes direction.


16

To determine when to split the rope, you must look at the area that the rope covers each frame. What you do is you do a collision check with the area covered and your level geometry. The area that a swing covers should be an arc. If there is a collision, you need to make a new segment to the rope. Check for corners that collide with the swinging arc. If ...


16

It's a while since I played Worms, but from what I remember - when the rope wraps around things, there's only one (straight) section of rope that's moving at any one time. The rest of the rope becomes static So there's very little actual physics involved. The active section can be modelled as a single stiff spring with a mass on the end The interesting bit ...


14

The video for Overgrowth Alpha 132 shows how they implemented ledge climbing: http://www.youtube.com/watch?v=GFu44oeLYPI Their method should work in any engine, even 2D engines where you'd use a rectangle and circle instead of a cylinder and sphere. Their ledge detection involves two parts: Wall detection (using the sphere) The game checks if the ...


8

One naive way of implementing it is by using raycasting. Calculate where your monster will be in some small chunk of time (probably a frame). From that position (or if you want to be more robust, that position +/- the bounding area of your enemy) do a raycast down. If it doesn't hit something within an appropriate range (depending on where you start your ...


8

One relatively simplistic way of doing this is to draw a ray from the center of the explosion to the center of every entity where DISTANCE(explosion,entity) < exlosion.max_radius (pseudo-code). For each entity, follow this ray, decreasing base damage as you go. Whenever you hit an object subtract it's cover value from the damage (essentially shortening ...


8

atan2 is a mathematical function; it is stateless. There is nothing in it to “know” that you want an angle which is close to the angle from the previous frame, as opposed to an angle which is simply sufficient to identify the direction. You must write your own logic to handle this case. There are several possible behaviors you could implement; here's the ...


7

If you look at the Farseer Physics Engine 3.3.1 Testbed XNA code, you'll find an example called OneSidedPlatformTest. Inside this test is the code required to create Fixtures that act in the manner you're requesting. Essentially, you override the PreSolve function in the following way: protected override void PreSolve(Contact contact, ref Manifold ...


6

Although in .NET value types are stored on the stack, resulting in a minimal allocation cost, it does not however eliminate the cost of initialization. In this case we have a set of functions using one or two temporary matrices, which would result in the initialization of 16-32 floats per call. While this may seem insignificant, if the methods are used ...


6

Well, you already have the tools, you just need to think of it differently. Rather than thinking trying to find empty space, you just need to find space with no collisions. Basically, all you have to do is test the area above the player with a rectangle the size of the player, and then if there are collisions, the player can't climb up. If there aren't ...


5

Steering behaviors work very well in combination with a physics-engine, as they are usually implemented in a way that they return a "steering force" which can then be applied to your physics-body. To make a unit follow a path, you could use Seek to go from path-node to path-node (make sure to avoid overshoot) and then use Arrival at the last node in your ...


5

Ok, after about two hours of tinkering I managed to do this but it requires adding some extra bodies. You'll probably want to extract this stuff into a method/class but the basic idea is this: Create what I call "holder" bodies for your objects. These bodies share the size and position of your "objects" but don't participate in collisions. Essentially, ...


5

The answer is simple: a physics engine is not a platformer engine. While you can get kind-of platformer-like behaviour out of a physics engine, you simply do not have enough control to get that really "fluid" gameplay feel of a proper platformer. For example: The classic Mario-style jump requires changing the gravity for the player at different stages of ...


4

I guess the revoulte joint is what you want. You can use it to pin the circle at a given position and the circle will rotate around that position.


4

Look at the reference of Matrix.CreateOrthographic, and notice that it says this: The viewable area of this orthographic projection is centered on 0,0,0. The x-axis of the area ranges from -width/2 to width/2. The y-axis of the area ranges from -height/2 to height/2. So, in your case, the upper border of the screen has an Y coordinate of -scale/2 instead ...


4

I haven't used it, but a quick google search turned up this thread. It makes sense since all physics engines, in my experience, give you the ability to apply impulses and/or forces. So look for the ApplyLinearImpulse/ApplyAngularImpulse functions. They enable you to specify points where you apply the impulse.


4

Farseer uses an iterative solver, so when your wheel starts colliding with another rectangle at high velocity, from time to time you'll see bumps since it's a "perfect align" to us, not to a physics simulation, with iterations things like these will never be "pixel-perfect". You will have to convert rectangles to Edge/Loop shapes and then model different ...


4

Do what your game does to start up. The simple, dumb way would be to re-initialize all your objects and variables as they do in the initialization of your game. You could be clever here, and only reload those elements that are modified during game-play (your models, maps, and textures likely don't change, for instance). If your character / gameworld has ...


3

Check out how the ninja rope in Gusanos was implemented: The rope acts like a particle until it attaches to something. Once attached, the rope just applies a force onto the worm. Attaching to dynamic objects (like other worms) is still a TODO: in this code. I can't recall if wrapping around objects/corners is supported... Relevant excerpt from ...


3

Finally works! I had the vertices of the contour as a sequence, so the solution was use the LoopShape to create the fixture of the body. I did not even know that Class =P LoopShape loopShape = new LoopShape(farseerVertices); //Delete the previous fixture farseerBody.DestroyFixture(previousFixture); //Create new fixture with the new contour ...


3

What I do is add a Texture2D directly to my game objects. I have another class called an AnimationController which manages my source rectangle/frames/timing for drawing animations from the texture. I suppose this would be similar to what your Sprite class does. If my game object will have a physics body (i.e. players, enemies, etc.), I add a Body property ...


3

Farseer does ship a physics view, and thankfully it requires very little brain power to implement and use. If you downloaded the "Farseer Physics Engine 3.3.1 Samples XNA" recommended package on their download page, you'd see a lot of examples included. Navigate to (or click these convenient links to the codeplex page :P) ...


3

float angle = MathHelper.ToRadians(45); float power = 20; // <- tunable value Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); fixture.Body.ApplyLinearImpulse(power * direction); The above applies an instantaneous force to the object. You could also set Body.LinearVelocity directly. To check for the space key being ...


3

Please take my answer as "the right way to do this", not necessarily the "good for a student project" way. Rigid body physics are entirely inappropriate for modeling "walking" behaviour. Rigid body physics are good for handling things like bouncing and friction. Which are things you want to avoid in a typical platformer. There is no "right shape" that will ...


2

Farseer Physics Engine's support of polygons is otherwise well-documented. Although the documentation may need to be updated to the latest version. You can create polygons using a list of Vertices; simply put the coordinates of all the corners. Vertices can either be defined in code, or be generated on the basis of an image file using some of the tools ...


2

It is actually really easy for (int i = 0; i < origin.body.FixtureList.Count; i++) { origin.body.DestroyFixture(origin.body.FixtureList[i]); } FixtureFactory.AttachCompoundPolygon(verticeslist, 1f, origin.body, null); return origin.body;


2

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it. This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1. So a lot of the time this error is ...


2

Here is my code for drawing Farseer debug objects. They line up perfectly with my real world objects. I had to play around with it for a long time before I got it to draw just right. This may be of use to you. Matrix proj = Matrix.CreateOrthographicOffCenter(0f, Viewport.Width, Viewport.Height, 0f, 0f, 1f); Matrix view2 = Matrix.CreateScale(32); view2 *= ...



Only top voted, non community-wiki answers of a minimum length are eligible