Jump to content
• Advertisement

# Magnet Physic's Problem

This topic is 2154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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.

#### Share this post

##### Share on other sites
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. Edited by max343

#### Share this post

##### Share on other sites
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;

#### Share this post

##### Share on other sites

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.

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites
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. Edited by max343

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5
• Advertisement

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633760
• Total Posts
3013721
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!