Magnet Physic's Problem

Started by
4 comments, last by max343 11 years, 2 months ago

I have an issue with a mechanic in a game I am working on. I attached a crude diagram I made in paint to help me explain my issue.

Blue Box - Dynamic Box

Black Box - Static Box

Red Arrow - Gravity

Yellow Arrow - Force from black box

Green Circle - Rang of Yellow Arrow

First diagram shows the blue box at rest being pushed down by gravity.

The second diagram shows what happens when the black box turns on it's opposing force.

The third diagram shows where I want the blue box to eventually come to a rest.

What currently happens is when the opposing force is kept on, the blue box goes to the highest point possible then falls all the way back down to black box and will continue doing that until the opposing force is turned off. I want the box to slowly level out and hover (like diagram three).

I am just looking for ideas on how you might handle it. Nothing I have come up with has worked.

P.S. - I am doing this in XNA using BEPUphysics engine.

Advertisement
What kind of repulsing force you're interested in? In other words, what is the nature of the force depicted by the yellow arrow?
If you don't really care about the nature of the force you can use damped harmonic oscillator to achieve the wanted effect. Otherwise you need to be more specific.
You need to dampen the oscillation. This is typically achieved by having some sort of drag. If your integrator has a line like this:
velocity += acceleration * delta_time;
replace it with this
velocity = exp(-some_positive_constant * delta_time) * velocity + acceleration * delta_time;

The above answer on damping is definitely the solution you're looking for, but I'd like to add that the idea of a "magnetic" field having only a certain "range" doesn't make sense. Both gravity and magnetism are governed by inverse square laws--that is, as the objects get closer, the force increases.

In these kinds of applications, you generally aren't considering gravitational force to change. You would model it as the (stable) equilibrium point where the gravitational force is exactly balanced by the magnetic force--if you go down, the objects get closer, and so the magnetic force gets stronger, pushing it back up. If you go up, the objects get farther, and the magnetic force gets weaker. Gravity takes over and pulls the object back down.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

I was thinking that the two forces acting on each other would cause a dampening to the oscillation, since when playing with magnets in real life they eventually came to a rest above the base magnet. I wasn't thinking about air resistance. I suppose if I took the same magnets in real life and put them in a vacuum they wouldn't stop either.

As for having a range on the magnetic field, I needed to do that in order to control how many magnets were acting on the player, otherwise it would result in quite a few game breaking bugs. Though I suppose if I had the magnets properly responding to distance it wouldn't be a problem...

Magnets behave differently than harmonic oscillators. In fact Lorentz force is much more complicated than just any restoring force. You can qualitatively understand the interaction process between two magnets by modeling them with currents in closed loops.<br />Modeling this effect with a damped harmonic oscillator is just a nasty shortcut, nothing more.

This topic is closed to new replies.

Advertisement