New answers tagged physics
0
It varies by game. Some try to model things physically using a physics engine and rely on friction to keep things moved together. This can be a bit fragile.
A more common technique that is used even in games (especially ones that don't have real physics support) is to just parent objects to others. If game logic detects that I've "landed" on a moving ...
0
It would be easier and faster to just remove the fixture on collision, instead of looping and checking for a string you set earlier.
I would update the OnCollision function as follows:
bool Player_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
{
//If category group 1
if (fixtureB.CollisionCategories == ...
1
Body.Dispose(bodyhere) is what you are looking for. It removes the body as well as all attached features. If you do not want to move Body.Dispose you can use World.RemoveBody(bodyhere) which removes the body after the current step. I would recommend you use the latter though.
1
You'll want to more than just add velocity every frame. That's basic Euler math, but doesn't work properly in a time sliced environment. Specifically, a variable framerate means that you'll get different results.
You'll want to do basic integration. There's a good article that goes into depth on that subject here: ...
0
Yes, that's how simplified gravity (or acceleration in general) works. You might want to limit your velocity (and gravity) to something (in reality: terminal velocity), e.g.
b_veloc_Y = std::max(-max_veloc_y, std::min(b_veloc_Y + gravity, max_veloc_y));
You might want to add some friction as well (maybe even make it velocity dependant) to lower ...
9
While the aerodynamic effects caused by a fan can be quite complex to model accurately, it is sufficient for most cases to model the force it applies after the Inverse-Square Law.
It means that the force it applies to another object is divided by the distance multiplied with itself.
Another factor you could or could not model depending on how physically ...
1
You could simply calculate the distance ( you can use any mesh for collision clipping to represent the "air flow" limits), the closer it gets the higher the force you apply to it in that direction. Of course this isn't as accurate, but you could add noise to the direction of the velocity.
1
Since I researched this in the past, I will post some code I had converted previously that may help you. This is basically the bare minimum of what you can do to achieve this effect. You will most likely want to add damping, and effects such as braking etc. It also works on a system where you only have two tires, one in front and one in back.
The code ...
1
Problem solved with:
world.ContactManager.PreSolve += new PreSolveDelegate(PreSolve);
0
Thanks to the contributors who answered this.
I went with my own solution in the end because it was simply enough to implement and gave perfect results.
All I had to do to scale the acceleration, was the following:
float fallAccel=(dt * num); //Where num is any arbitary amount and dt is the delta time between frames (hence it is scaled and also ...
0
Ok, so I haven't seen anyone answering with a solution for ignoring collusion between certain prefabs without assigning them their own layers (which are limited to 32).
So it's clear that in current unity versions, you must call IgnoreCollision() for each pair of instantiated objects.
So the solution I found, is an old one (before the layers were ...
3
Part of the problem is that your notion of 'velocity' isn't physical. Your updating of position is fine:
spriteYReal = spriteYReal + (spriteYVel * dt);
sprite.yScreen=(int) (spriteYReal*r.height);
This just says that the sprite's position is computed as Pnew = Pold+V*dt, which is fine - it means that V=dP/dt, which is correct. The problem is that the ...
0
Physics update rate must be independent from rendering frame rate. Becase it's not exactly 60 fps.
void update( float dt )
{
float maxStep = 1/60.0f;
if (dt > 0.25)
dt = 0.25f; // note: max frame time to avoid spiral of death
accumulator_ += dt;
while (accumulator_ >= maxStep) {
physical_world_->Step(maxStep);
...
0
Trying to ignore collisions between certain prefabs, but in this case
I don't want to use layers since these are specific object pairs that
I want to not collide
When you have specific objects pair that you don't want to collide, using layers is definitively the best way to go.
creating a layer for each prefab would complicate the layer matrix
...
0
The topic is too broad to benefit from a single answer on this site.. but some better things to do can be covered nonetheless:
investigate continuous collision detection/simulation strategies
use ray casts and/or shape casts to detect collisions AND the TOI (time-of-impact)
once the time of impact is computed, it gives you the time the object will travel ...
0
There are many ways to handle collisions in your game.
One possible solution is to revert to the position before the collision happened, like the first method you mentioned. I would advise against this solution. It gives a weird feeling when you are playing and prevents you from "sliding across a wall". I used to handle collisions like that. I wish I ...
1
Do you evade in the sense of "to flee" or "to (non-)cooperatively walk around each other"?
The answer to both questions is quite easy:
1) To let A flee away from B... let move A in the direct opposite direction of B relative to A. Which means: The direction vector should be Position(B) - Position(A). You'll then need to calculate the angle from this Vector ...
6
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 ...
0
Vertices is in Farseer, in the namespace FarseerPhysics.Common:
using FarseerPhysics.Common;
1
In addition, the ball jumps weird when it touches two platforms at the
same time. Is there a possibility to avoid that weird jumping?
Nope your going to get that behavior with 2 platforms. You should combine them together into 1 shape. If the shape is more complex you can create a polygon that encompasses the entire area.
Anyways friction is going ...
1
Found the solution to my problem. I simply needed to set model's origin in Sketchup to its bounding box's center, now bullet works correctly in my scene again :)
2
Are you just adding force to the ball? If you need elastic collisions don't do this.
Farseer body has property called restitution, it controls ratio of the speed before and after collision.
0
I am not a Ogre user, but I really think your problem is related to the createBox() call.
Since you loaded your later cube from a mesh file, it is a regular convex mesh, not necessarily interpretable as a box by BtOgre. Calling createConvex() instead would probably fix it.
This is because the loaded cube would be now treated as a mesh, which happens to be ...
0
Each body finds the bodies closest to it. It then attempts to steer away from the sum of the neighbors. The closer a neighbor is, the more it adds to the repel force.
If each body does this, they will spread out away from each other. This combined with a cohesion algorithm keeps the bodies grouped, but not on top of each other.
Both of these are ...
0
There are plenty of tutorials for both libraries. For Farseer, I recommend to check out the "Getting started" section of their document, which also links to a Box2D manual for further reading: http://farseerphysics.codeplex.com/documentation?referringTitle=Home
You can then take a look at the Farseer Examples and try to understand how they work. The Basic ...
0
Friction
You probably missed friction, in water that is a velocity dependent force working in the opposite direction of the velocity. For light voluminous objects the friction will counteract buoyancy very quickly.
Try pushing a beach-ball either a half or a whole metre under water and let go, you'd think the whole metre would give double the jump height, ...
2
Here's the correct code :
Vector2D weight(mass * gravity);
Vector2D buoyancy(immersedArea * fluidDensity * -gravity);
// assuming operator overloading of +
Vector2D totalForces(weight + buoyancy);
object->applyImpulse(totalForces);
In your code, you calculate mass * area_ratio * gravity but the weight does not depend on the immersed volume ...
0
"current_weight" isn't a function of area_ratio. Weight is just the force of the mass affected by gravity, F=ma or W=mg. The boat will always have the same weight in the direction opposite gravity, but that force is counteracted by buoyancy.
http://www.engineeringtoolbox.com/mass-weight-d_589.html
Try removing area_ratio from your current_weight ...
1
So, as per Mr. Geerkens suggestion, for the sake of completeness, here is the answer to the question.
A fantastic example of cloth simulation using a variety of integration methods can be found here. It has explicit and implicit methods, IMEX, FEM, runge-kutta and verlet. It comes with complete source code that is easy to understand and easy to compare to ...
7
found a detailed breakdown of Mario Physics:
http://forums.mfgg.net/viewtopic.php?p=346301
http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
3
Here are 3 standard (pre-calculus) kinematics formulae covering the case of constant acceleration, each with one of the unknowns (t, v, or _d) eliminated:
v^2 = u^2 + 2 a d
v = u + a t
d = u t + a (t^2) / 2
where:
u and v are the unitial and vinal (sic) velocities respectively;
t is the time;
d is the distance travelled in time t; and
a is the constant ...
1
In X Men 2, Magneto shatters his glass prison with several marble sized metal balls, youtube.
In the DVD commentary the designers explian how they did the breaking effect. It was too computationally intensive to fully simulate it, instead they had an artist determine where the breaks would be (and where they'd look good). Then they scripted when the pieces ...
4
I assume by "real" physics you really mean "realistic" physics. In almost every game that includes physics, unless it is a key feature of the game, the developers will take shortcuts to reduce processing time.
Quick answer: fake it with an animation.
Little longer answer: Reduce the number of pieces you process. You'd be surprised by how much time you save ...
0
I had this problem and for me the solution was providing perfect restitution.
So for me that is sqrt of 0.5 for all objects. Because sqrt(r1*r1 + r2*r2) == 1 in perfect situation.
0
I use level director (www.retrofitproductions.com/level-director) and PhysicsEditor by codeandweb.
Physics Editor will allow you to apply the physic properties and body shapes to each object and Level Director will allow you to import them and then setup the complex bodies and joints as needed.
Once done, Level Director allows you to export the data in ...
1
Ok so I finally managed to work out what I was doing wrong.
The issue was how I was applying the rotation vector to the quaternion. Basically rather than use Quaternion.CreateFromAxisAngle() I now create a rotation change Quaternion using my angular velocity as the X,Y,Z components and 0 for the scalar. So just for clarity here is my new update code for ...
1
I tackled this problem recently using some of these answers as a starting point. The most helpful thing to keep in mind is that boids are a sort of simple n-body simulation: each boid is a particle that exerts a force on its neighbors.
I found the Linde paper difficult to read; I suggest instead looking at S.J. Plimpton's "Fast Parallel Algorithms for ...
4
In light of your question's context, http://nodewar.com/, there are a couple specific considerations for your solution:
You have a (low) maximum angular velocity, and enough maximum torque to reach it in very short time.
Your drone and target each have velocity and external acceleration unrelated to thrust (gravitation abounds).
Your desired target changes ...
3
A similar question, with some good answers, including the apparent name of this whole subject, "motion planning":
http://stackoverflow.com/questions/2560817/2d-trajectory-planning-of-a-spaceship-with-physics
As a programmer, I like the practicality of user470365's suggestion. However, I'll take a stab at a more rigorous approach. My suggestion here computes ...
1
Here's a different algorithm; instead of stepping the player forward and moving him back if he's colliding, check where the next collision will occur:
Get the position of a corner of the object.
Shoot a line down (or up, or to the right/left, depending on your movement direction) from that position.
Figure out the first place that line intersects a ...
0
It seems from your picture that you want the path to be straight, which is not what would happen if the ball was subject to gravity. Also from your description, it sounds like you want the ball to come to a sudden stop before accelerating downwards again.
Anyway, from what I understand of your problem, here is how I would solve it. If I have misunderstood ...
2
Demonstration:
Crude but functional collision detection and response
Video:
https://vimeo.com/64923588
The idea is that the player controlled sprite (actually a 32x32 pixels red box) can raise the speed of its next move, but it cannot go back to original speed except if it collide with something. Also if speed is enough the green wall can be "damaged" ...
Top 50 recent answers are included




