Tag Info

Hot answers tagged

2

Approach B is what you want. With Approach A here's a possible problem: //You have two balls //Ball A moves //Ball A is now colliding with Ball B //Ball A and B get forces applied When in reality Balls A and B are very close but have the exact same velocity! What should happen (and what you would get with Approach B) is: //Ball A Moves //Ball B Moves ...


2

Vector mathematics! Assuming you're using Unity, you could use the inbuilt functions of Vector2: transform.position = Vector3.MoveTowards(transform.position, target, speed); Otherwise, here's how it's done - first, calculate the direction from point A to point B: public static float Length(float x, float y) { return Math.Sqrt(x * x + y * y); } ...


2

For a really good and in-depth article on this subject, just read Fix Your Timestep. There's also a ton of existing questions about this subject, although addressing different angles. But in really simple terms, this is how you get a fixed physics (or anything, really) frame rate despite the rendering frame rate being unpredictable: loop check how long ...


1

CharacterController controller Has a radius and height that define its space occupation. (the green cage in the image). That cage (capsule) interact with othe colliders (i.e : the terrain). If the cage its too big respect the enemy shape, you see it fluctuate, because the cage bottom touches the ground.


1

It's been a while since I did anything like this, but if I recall correctly you want to test a point on the circle against the line that defines the wall, and if the point has bypassed the line (IE, the line is closer to the center of the circle than the radius of the circle), a collision has occurred. The "pushing" effect comes from blocking the ability to ...


1

The Wikipedia article on collision detection has this to say on the topic of matrices and collision detection; So we reduce the problem to that of tracking, from frame to frame, which intervals do intersect. We have three lists of intervals (one for each axis) and all lists are the same length (since each list has length n, the number of bounding boxes.) ...


1

To do this, firstly you need to define a physics update time period (say, evry 16ms) and then you need to handle the case of when your game runs too fast, and when it runs too slow. When the game runs too quickly (faster than your physics update period) you need to interpolate between the last physics frame data and the next physics frame data based on what ...


1

Shortly after posting I tested this out a bit more and found that the assert will fail. GetFixtureA() may or may not return a fixture belonging to playerPhysicsBody. I'm now using this convenience function to safely find the fixture that I want: inline const b2Fixture *contactFixtureFor(const b2Body *body, const b2ContactEdge *contactEdge) { return ...


1

There was something wrong with my collisionNormal method, where the left and right vectors were actually flipped. This made collisions along the x axis actually push the objects into each other. if (wy > hx) { if (wy > -hx) { /* collision at the top */ return new Vec2D(0, -1); } else { /* on the left */ return ...


1

Both ideas are actually correct, but the second code snippet seems wrong to me. If it is the same get_drag() in both cases, then it should operate on a scalar, and return a negative number. It should be something like: drag = v # No sign inversion here; get_drag() does it drag.normalise() fd = get_drag(length(v)) # Operate on a scalar drag ...


1

All free rigid bodies will rotate about their center of mass, so you're kind of stuck in that regard. However there are two options: Implement an artificial pivot (specify the coordinate that you want it to pivot about) and do summation of moments about that point. This would require a modification to existing physics fxns, or a new fxn. Temporarily store ...


1

Velocity is speed and direction, and the only tricky part is the direction. Your question cuts right to that problem. This kind of vector math is linear algebra 101. However, since Wikipedia offers its usual incomprehensible notation for otherwise simple mathematics, here's a quick summary. The vector from P1 to P2 can be found by subtracting: v = ...


1

It turns out that Farseer objects can have multiple restitution and friction settings: one set for the body and one set for each fixture. I was only setting the body settings; adding settings for the fixtures solved the problem: fixture.Restitution = 1f; fixture.Friction = 0f;


1

Looks like you're mixing 3D & 2D physics. You're using OnCollisionEnter2D, which triggers when 2D colliders hit each other. But then you're using Physics.Raycast, which casts rays against 3D colliders - so it won't be able to detect the two colliders that triggered the event, or any similar colliders in your scene. Maybe you want Physics2D.Raycast?



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