Jump to content

  • Log In with Google      Sign In   
  • Create Account


Magnet Physic's Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 XwingVmanX   Members   -  Reputation: 108

Like
0Likes
Like

Posted 23 January 2013 - 01:40 PM

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.

Attached Thumbnails

  • Diagram.png


Sponsor:

#2 max343   Members   -  Reputation: 340

Like
0Likes
Like

Posted 23 January 2013 - 01:56 PM

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, 23 January 2013 - 01:57 PM.


#3 Álvaro   Crossbones+   -  Reputation: 12353

Like
0Likes
Like

Posted 23 January 2013 - 02:03 PM

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;


#4 Geometrian   Crossbones+   -  Reputation: 1449

Like
0Likes
Like

Posted 23 January 2013 - 04:55 PM

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.


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.

#5 XwingVmanX   Members   -  Reputation: 108

Like
0Likes
Like

Posted 24 January 2013 - 02:11 AM

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



#6 max343   Members   -  Reputation: 340

Like
0Likes
Like

Posted 24 January 2013 - 03:55 AM

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, 24 January 2013 - 05:04 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS