Download

"magnetic" hover vehicle

Hi!

I want to create futuristic racing vehicles that magnetically attact the track they drive on (so i can drive huge loopings, or for example if i would jump over a hill it wouldnt jump away because it will stay atracted to the track)

Is there something that logically can do this or do I need to “cheat”? (fastpaced multiplayer racing game so nothing to fancy/expensive)

to avoid confusion about the hovering, its like this https://www.youtube.com/watch?v=cPVaDndT7tY, so the magnetic part would apply to the whole vehicle or the bottom of the hovercomponents.

The idea is to make it possible to drive crazy tracks (like head first parts, or prevent the vehicle from flying away like a paper plane on crazy mach 1 speed-over 100% slope - downhill parts)

That all “magnet style” so if youd take a weaker magnet you would fall off easier. (so not like a fixed spline/plane/rail system where its impossible to get off…)

a quick sketch

You can use hover vehicle tutorial that you’ve linked as a base and modify hovering function. Something like this should work:

  1. Do a LineTrace from your magneto “wheel” from it’s root downwards, length of the LineTrace should be something reasonable where you think your magnetic force should be active
  2. Define a variable to represent a “sweetspot” height at which vehicle should hover, let’s call it DesiredHeight
  3. LineTrace give you a distance at which ray collided with something, this would be ActualHeight variable
  4. What we want to do now is construct a sort of spring which will push vehicle away if it’s too close to track and pull it back if it’s too far away from track
  5. let’s calculate spring ratio:
    SpringRatio = (DesiredHeight - ActualHeight) / DesiredHeight
    notice that spring ratio can have both negative and positive sign, this will pull or push spring
  6. Spring itself can be described like this:
    SpringForce = ActorUpVector * SpringStiffness * SpringRatio
    we want to push vehicle upwards if SpringRatio is positive. SpringStiffness is what you need to tweak, good value to start from will be more or less equal to force of gravity acting on vehicle. SpringStiffness ~ MassOfVehicle * 980 / NumberOfMagnetoWheels, just calculate it in spreadsheet and later tweak it to be a bit higher/lower
  7. At this point you could already apply SpringForce as AddForceAtLocation() to the root body, unfortunately it won’t work nicely because springs will keep oscillating, we need to add dampener and for this we need to change SpringForce formula:
    SpringForce = ActorUpVector * SpringStiffness * SpringRatio - SpringDampening * SpringVelocity
    SpringDampening is usually very small value in comparison to SpringStiffness, so if your SpringStiffness is somewhere around hundreds of thousands then SpringDampening would be few thousands.
    But first we need to find SpringVelocity, for this, on every update you need to store ActualHeight, at the end of update, into a variable. Let’s call it PreviousActualHeight, so at the end of each update you just do PreviousActualHeight = ActualHeight.
    Now we can find velocity:
    SpringVelocity = (PreviousActualHeight - ActualHeight) / deltaTime
  8. Finally calculate SpringForce and apply it as AddForceAtLocation(SpringForce, LocationOfMagnetoWheel) to the root body

There was some topic recently with similar problem to yours. We had a bit of communication problem there, so some of posts do not make much sense.
But i created hoover project for that guy: Dropbox - Error

Tupic:

Sadly it turns out that having more than single thruster flips car over due to pendulum effect.

I also created another version of that project with single thruster and stabilizing code. That version could potentially work for you. Sadly i had no time to finish stabilized version.
Biggest problem with it is to calculate force that should be applied, If you do it only as reaction to position and speed it will indice that pendulum stuff (like hoover version from dropbox).
You need to calculate optimal response (which is not trivial math). Damping does not solve problem, it only delays its appearance and slows it down.

How to make 1 thruster and base setup for stabilized vehicle:

  • create sphere collision (and use it as physics mesh), angular stabilization is whole new can of worms, so first you should do code for just hovering ball vehicle.
  • create one thruster that is in exactly center of mass (sphere helps here)
  • from center calculate 3 vectors (that form triangular pyramid and point down)
  • trace line along all 3 vectors, get hit locations on ground
  • from those 3 hit locations create 2 vectors: vector_0 = hit_A - hit_B and vector_1 = hit_a - hit_C
  • now calculate >CROSS PRODUCT<, its result is normal vector right below your vehicle.
  • decide on optimal distance from grould.
  • now develop your optimal stabilizing code here, that you will share later with rest of us.
  • or use very siple one: if ball is below optimal distance push it up, if its above push it down (as done in that youtube tut you posted, but for pushing down and up)

BTW @BoredEngineer

Can you by any chance make formula for calculating that dreaded optimal force to stop pendulum woobling? I gave up when i seen laplace equasions, I am not in mood for refreshing that stuff (I rather dig in more into unreal engine).

Just to understand better what the problem is, perhaps what you experience is similar to car suspension without anti-roll bars. Meaning that when you accelerate, turn or driving over the curb, mass of the vehicle dynamically shifts so your suspension/thrusters need to produce different amount of force then in static case as they experience more mass pushing on them. For example, car without anti-roll bars turns left, as car still has inertia which keeps pushing it forward, there will be more mass pushing on right suspension and less mass pushing or left suspension. Which will start flipping car even further to the right, as the net result of gravity force and suspension force will be lower than normal and on right side it will be higher than normal.
What anti-rolls bars do is transfer some of the suspension force from one side to another to balance them out.
Just a formula won’t help, you need a bit of algorithm to solve this. Here is a good explanation of how to code it:

Ohh, wait, I had what one would call a woobling effect on Ripsaw after doing some tweaks in suspension. The solution was very simple, just lowering center of mass by 10 cm down. The reason for this bug was because points at which suspension/hovering forces are applied where almost exactly on the same plane with center of mass. By lowering center of mass, suspension needs to do more work to rotate vehicle, so rapid changes in force from frame to frame are eaten by rotational inertia.

It usually resembles pendulum movement (because by reacting only to location and speed, your simulation works almost like gravity does).

So if i want to keep hovercraft at 1000 units above, if its below i push it up, when its up i push it down. Task is to find optimal force that does not push too hard, and instead approximates strength so hovercraft stops at 1000 units. That is very common problem for automation and control theory, it is most basic stuff (because we have linear function here), but gets very complicated when you want to find optimal steering. I could even find formulas, but those are some Laplace functions, converting them into script that calculates discrete response is something i do not want go back into. I hoped you know that automation stuff, your response looks like your nick is not far from truth.

It is not only problem with hoovercraft, first time i faced it was when i wrote AI for spaceship (restrained only to 2d plane for easy testing). I could not make spacecraft stop at destinations, It always went into some circles around, because my script was over-steering with forces applied. Then was that French guy having same problem with his game, it tok a while for me to realize its not camera problem but his pawn is rolling madly. Now this topic about hoovering craft, that need 3d stabilization over some track, which is most complex case so far.

I probably will tackle it again when i code hoovering drone AI, but knowing math behind it, looks like quite challenge. Unless i find formula or algorithm for finding best response.

I have some glimpses of memory how steering graph force for this should work (x=y^2) or something very similar, i kind of remember shape of graph.
So solution may be quite simple: use blueprint function node, find that graph on internet, recreate in unreal, and apply result as force.

This is something like is needed here: http://blog.wolfram.com/2011/01/19/stabilized-inverted-pendulum/

And this is math, but it gives me shivers when i look at it.
http://www.engr.iupui.edu/~skoskie/ECE680/ECE680_l3notes.pdf

Thinking more about it, this topic case needs inverted pendulum stabilization to stay on track (and do not do random barrel rolls), and keeping distance from ground probably can use same formula.

I see what you mean. Honestly, I don’t know how to fix it in general case. Specifically where I had to deal with this issue is suspension for Aerosled, in comparison to tank it had only 4 springs (tanks had at least 10) and I had to tune in a bit better.
But in both cases “over-steering” of the spring was fixed by dampener, just as in real-life spring suspension. By dampener I don’t mean linear or angular damping constants but this linear damping: Damping - Wikipedia
The only problem with it is high dependency on delta time. Over some step of delta time both spring force and damping force are going to overshoot as we are dealing with a discrete time steps and limited float precision. Specifically for this issue, one of the solutions is to get higher refresh rate for physics - sub-stepping. The other solution is to use different integrator like RK4 or going with explicit solution, if it’s available.
To my understanding you have to go with more complicated solution when your control forces are discrete. Like majority of rocket engines don’t have a variable thrust and take slightly variable amount of time to get to the full thrust. Or when you have an aerodynamic steering on missile and you have some minimal degree at which you can move your control surface, so by design your controls will always over-steer. Yet again higher refresh rate of your calculations will help tremendously as you can calculate not only necessary force but necessary time when to apply it.
My interaction with control theory was back in university many years ago, I’ll check that article to better understand what you mean.

What do you mean by random barrel rolls? (I can’t check dropbox project right now)

this is my reply. :smiley:

Because it is simulation, so kind of quantized time and impulses, and simulation gives funny glitches sometimes. Even smallest assymetrical rotation usually increases over time, and without stabilizing code it just flips vehicle over. And that is on flat horizontal surface, he want to have that track in 3d. Vehicles will do random physics glitches all the time, preventing that is hardest part of coding such game.

Sorry for that edit, its to easy to click wrong button.

It’s not too different to mechanical engineering as you can’t physically calculate and simulate everything. Sometime you can use wisdom from engineering field to see how they build their stuff more stable or self stabilizing.
Personal example. I have an old 4.3 prototype for airfoils, which I’ve used to make a simple physics driven airplane. There were some small asymmetry of fuselage and perhaps my custom meshes of wings where not 100% symmetrical (or maybe bug in the code or order of update), as a result airplane kept slowly banking on one side. I didn’t had any trimmer and was slightly annoyed by this “emergent” behavior of model. Few days later I’ve bend wings upwards by a very small degree, so that lift vectors on both wings are slightly pointing towards each other instead of being parallel. As a result, the whole issue was gone as such configuration will try to self level itself. It’s used in airplane design, where I got this idea by reading few articles.
Cars or other machines with suspension have similar considerations, like this one: http://www.meganracing.com/tech/faqs.asp?id=106&subject=Suspension
Similar thing for ships: https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Ship_stability.svg/2000px-Ship_stability.svg.png
From my experience, it’s easier to make sure that your “machine” follows considerations of the real thing than try to fight all kinds of precision and variable time step bugs.

For some cases this won’t work, as for example modelling of something like SR-71 will require to have unstable aircraft, this is where smarter control systems and higher precision simulation is a must.

Yes doing more realistic models may be way to go.

However my idea is to use invisible spherical mesh that simulates physics only, then use another mesh that is visible but does not simulate physics. All code needed would be to orient that visible mesh to match normal vector of track surface.

But then this project wants loops on track and all that stuff. And proper code for applying correct forces to stay on track also requires that steering solution.

Anyway i will play with it, its also on my todo list.

The physics are close to the same of boat simulation, there’s some articles about it out there, gamasutra, etc.
To make the track loop possible for the ‘boat’, a cast from the center of mass to local -Z must take hit normal and set actor’s gravity vector to the resulting normalized vector.

I’ve checked “stabilized inverted pendulum” article. Correct me if I’m wrong but to achieve this you need have a mathematical description of your model. Take into account that example in the article is very simplified in a sense that control is done to keep single specific angle of rotation and X position. I’m afraid that if you unwrap it for 3D case you will need more than a single matrix as a result of StateSpaceModel. Nevertheless it’s really cool approach to solve such problem. Looking forward to read more about this.

Ok, Nawrot,
in context of this article, what you want to build is something like a 2 dimensional seagway? This is why spring and dampener suspension is out of question for you. I was thinking about building a tracked motorcycle and use shifting weight as a control mechanism, but I see that it can have a problem with oversteering unless there is some other force which helps to balance it out. Bicycles and motorcycles have this force but you are looking into something like a unicycle.

To be fair OP clearly has 3 “wheels” on his sketch. So he might solve it in a simpler way.
With vehicle like this I’m more curious about steering and how to get them not skid all over the place.

Can someone post an image for how the blueprint is set up for 4.15, for some reason the whole thing doesn’t work anymore. It’s failing to set simulate physics so the mesh just remains stuck in mid air and doesn’t even fall.

My plan is to create a vehicle known as a Sphirvo which hovers using air suction (such like a hovercraft) to easily travel from places more efficiently. Here is an ideal image, but I will send a new one to improve my theory which should change: