Anti-Gravity vehicle bounce-back?

Im making a game where you fly an anti gravity vehicle (ufo) using proper rigidbody physics not hackish transform.translate methods, the game is in like pre pre alpha so i dont know what im gonna do with it.

but the problem is.

when i activate the antigravity mode for the saucer, and start flying but when i collide into an object and the saucer tilts when collided, what i want to do is make the saucer automaticly bounce smoothly back when it tilts to its original rotation using proper rigidbody methods.

but i have no idea how to code that.
thank you in advance, really apreciated.

There are many ways to do this and they are all difficult ! Heh

You have chosen quite a challenge for your project.

One method: have an invisible UFO that flies along, and that is locked (look at your inspector, rigidbody, constrain) so that it stays straight and level.

Then, your “actual visible” UFO … attach it with a Spring to the “actual invisible!” ufo. The “visible” ufo will bounce around nicely, but always come back to square and level in time.

This will produce one look that may be what you want.

The fact is - you’ll have to master this technique and many others!

Another thing you will have to learn about is AddTorque

notice the various functions you have available to you here:

Just like you, I rarely use “hackish kinemantic” rubbish - I like to use “real many” physics! :slight_smile: In fact you will have to get really good at using AddTorque. Basically you’ll have to look at how the object is currently rotated, and apply a little torque against that. it’s not easy but you can get there! Again - you’ll have to master this technique and many others!

Now here’s an example “UFO ATMOSPHERIC DRIVE” motion rig:

(1) Open Unity

(2) Make new project

(3) click “create cube”

(4) click on the cube. click “add rigidbody”.

{As everyone knows, a typical UFO “weighs” about 900 kg {Reference … “Above Top Secret”, Timothy Good} Obviously, UFO engineering concepts include from the ground up modification of what we Earth scientists have recently laughably referred to as the “Higgs field” so you can’t really just give the mass of a UFO in the atmosphere. But we can take 900kg as a good “simulation figure” when we are making a video game based on UFOs - so let’s do that.}

(5) So in the Inspector, rigidbody, set Mass to 900 kg

(6) click “new javascript” Name it “teste.js” Paste in the entire script below… continued below


// teste.js

// example rig to make one aspect of ufo-like hovering motion

// attach this to a CUBE WITH RIGIDBODY in Unity

#pragma strict

private var plusMinusStyleTwists:Vector3;

function FixedUpdate()
	plusMinusStyleTwists = transform.rotation.eulerAngles;
	plusMinusStyleTwists.x = _fix( plusMinusStyleTwists.x );
	plusMinusStyleTwists.y = _fix( plusMinusStyleTwists.y );
	plusMinusStyleTwists.z = _fix( plusMinusStyleTwists.z );
	plusMinusStyleTwists = -1 * 12.0 * plusMinusStyleTwists;


function _fix( tt:float )
	// note that rotation.eulerAngles is just expressed as 0 to 360
	// of course we must change it to -180 to 180
	if ( tt > 180.0 ) return ( tt - 360.0 );
	return tt;


(7) drag your Teste to the cube

(8) click Play

(9) click on the Cube

(10) click “E” on your keyboard

(11) notuce the three read circular draggables. grab the red one and disturb the cube about 20 degrees

(12) notice the Cube has an interesting behavior, it comes back to the middle. try disturbing all three of the circles and see how the Cube bounces around

(13) And now the critical part of the recipe. Click Stop. Look at the Inspector Rigidbody. Discover the ANGULAR DRAG one of the most important settings in a physics engine. It ranges form ZERO to ONE. Personally I like the highest setting for this ufo, 1.0

(14) note in the code i multiply the Degrees amount of “about 12”. I just guessed that as a figure that works well for the 900 kg atmospheric mode UFO. Annoyingly, Unity/PhysX does not really (as far as I know) properly offer proper newton-metre (or even Joule-radians) measurement of Torque - so essentially I’ve just tooted around there with a rough and ready approach. In a real project you would use radians and do proper engineering.

Note too that I simply have a linear relationship from the angular disturbance to the “atmospheric mode balancer engine-like device” (AMBELD) in the UFO. Naturally, you would have to properly work out the response of an AMBELD and simulate that. (almost certainly it would decrease asymptotically, perhaps the 2nd or 3rd power, as it goes closer to true).

Finally this is of course a crappy solution that doesn’t address gimbal lock, you’d have to take simple measures to avoid that problem.

Hope it helps get you started!