Hi everyone!
I have a “hover craft” that works almost as desired, except its a bit jittery
When you go straight and slow down it’s okay, but as soon as you turn and slow down the background looks jittery even at 600 fps+…
Here’s my code so far.
var desiredHeight = 1.0;
var spring = 100.0;
var damp = 10.0;
var SpeedMovement = 5.0;
var turnSpeed = 5.0;
var movDir : Vector3 = Vector3.zero;
var rotDir : Vector3 = Vector3.zero;
var attachedRigidbody : Rigidbody;
function Update() {
if(rigidbody.angularVelocity.magnitude > 2)
rigidbody.angularVelocity = rigidbody.angularVelocity.normalized * 2;
}
//HoverCraft Hovering
function FixedUpdate() {
var cam : Transform = Camera.main.transform;
var hit : RaycastHit;
var up = Vector3.up;
if (Physics.Raycast(transform.position, -up, hit, 100.0)) {
// Force required to negate gravity
var neutralForce = rigidbody.mass * Physics.gravity * 0.2;
var yDifference = (hit.point.y + desiredHeight) - transform.position.y;
var addForce = yDifference * spring;
addForce -= rigidbody.GetPointVelocity(transform.position).y * damp;
rigidbody.AddForceAtPosition(neutralForce + addForce*up, transform.position);
rotDir.y = Input.GetAxis("Horizontal") * turnSpeed;
movDir.z = Input.GetAxis("Vertical") * SpeedMovement;
// Calculate the x-axis relative to the camera
var cameraRelative : Vector3 = cam.TransformDirection (movDir);
// Apply a force relative to the camera's axis
rigidbody.AddForce (cameraRelative);
rigidbody.AddTorque (rotDir);
//transform.rotation = Quaternion.Euler(cameraRelativeRight);
}
Debug.Log(rigidbody.angularVelocity.magnitude);
}
Thanks,
Theokie