- Home /
C# - Wipeout style Hovercraft effect
Greetings guys , I've been trying to archieve a hovercraft effect like shown in this video below for quite some time now : https://www.youtube.com/watch?v=3xWfBgtI_BA i want it to stay on the ground and be aligned to the surface below it and not go too far away from it but i can't get it to stay on the ground no matter what i try . it either flips over or it goes flying and takes ages to come back down. i'm using a rigidbody so i can't align it to the ground normal directly using the transform class . Please answer if you have any idea how to recreate this effect i've been stuck on this one for a long time and it's getting on my nerves
Answer by Cherno · Mar 25, 2015 at 10:06 AM
There's a buyonacy script designed for boats and other floating objects on water over on the forums, maybe it can serve as the base for your own script.
To keep the craft aligned to the ground at all times, ust cast a ray downward (in world space) and slowly rotate the craft towards the normal vector of the surface the ray hit.
private Quaternion rotCur;
Ray ray = new Ray(transform.position + Vector3.up * 1.0f, -Vector3.up);
RaycastHit hit;
void Update() {
if(Physics.Raycast(ray, out hit) == true) {
rotCur = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
}
transform.rotation = Quaternion.Lerp(transform.rotation, rotCur, Time.deltaTime * 5);
}
Thanks for the reply , That would work on kinematic - non rigidbody objects but since my configuration uses a rigidbody adjusting it's transform component directly would be a really bad idea ( major glitches and instability ) . so not an option for my case
Well, you could still make it rotate towards the ground normal by using AddTorque, I guess.
I'd bet dollars to donuts that vehicle in wipeout does not use rigidbody physics in the way you're trying to. The reason you can't make this craft stable with rigidbodies is, you are literally trying to engineer a physically accurate hovercraft dynamics simulation. That's a job for the R&D $$anonymous$$m at Lockheed $$anonymous$$artin. I have trouble counter-balancing my ceiling fan.
If your heart is set on rigidbodies, consider this: Find the ideal position and orientation using the methods described here, and use that data to directly set the transform values of a dummyTarget object. Have your rigidbody use "real" physics to attempt to come to rest in the same pos/rot as the dummy.
I won't say it's impossible to achieve a relatively stable pure physics implementation your way in Unity, but I'm not the least bit surprised to hear it's a pain in the butt to get right.
I don't want to necessarily use rigidbody physics to archieve that . i just want it to look almost like in the video or some pointers / tips on how the guy in the video might have done it that's all
Answer by AlwaysSunny · Mar 24, 2015 at 06:10 PM
Based on how that vehicle behaves, I'd hazard to guess they are not using "pure" physics to drive its behavior. It's more likely a carefully tailored simulation specifically designed to achieve these effects.
That's not to say you can't re-create the behavior with Unity's physics sim, but you should not expect the task to be simple.
I observe two distinctive behaviors in that video: self-righting, and hovering-suspension. These should be treated as separate-but-equal behaviors.
I've never done this, but my first thought WRT using Unity rigidbodies to duplicate the effect is:
Have several feelers (raycasts) in the "down" direction of the craft's belly, and several "down" in world space, cast from the same points. (nose, tail, wing tips). Comparing the hit.normal of the "belly out" feelers to the "world down" should give you useful data about the terrain beneath the craft and the craft's orientation relative to a flat plane. You can use this data to scale the forces you apply "up" from each point (AddForceAtPoint). Also, the distance of the hits on both sets of feelers will help drive "upward" force to produce the lazy suspension effect.
The self-righting behavior might apply the torque necessary to suggest a "belly level with terrain below me" orientation depending on what the feelers are reporting, so that you only self-right when necessary.
I guess a third need emerges here; maintaining position. On an incline, these two behaviors alone will encourage the craft to "slide down" hills. This is a complicated desire, I'm afraid. Honestly if I could, I think I'd avoid using rigidbodies for this task altogether. These behaviors are not physically realistic in the first place.
I've actually already tried the suspension method described in your answer it still had the craft flip over and fly too high from the ground . i don't $$anonymous$$d it sliding , i just want it to stay aligned at all times while maintaining a low distance from the ground
Your answer
Follow this Question
Related Questions
first person controller prefab falls through floor 1 Answer
Destructible ground? 2 Answers
Irregular ground collision 1 Answer
Splatmap dry/healthy 1 Answer
How can I add Normal mapping to a Terrain custom shader? 0 Answers