Skip to content

Instantly share code, notes, and snippets.

@hellos3b
Created November 3, 2017 18:56
Show Gist options
  • Select an option

  • Save hellos3b/626460b44a66b2dfa875c995300b3dd1 to your computer and use it in GitHub Desktop.

Select an option

Save hellos3b/626460b44a66b2dfa875c995300b3dd1 to your computer and use it in GitHub Desktop.
void FixedUpdate () {
if (input2.y < 0) {
InputDirection.y = Mathf.Clamp( InputDirection.y - pullSpeed * Time.fixedDeltaTime, -1f, 1f);
} else if (input2.y > 0) {
InputDirection.y = Mathf.Clamp( InputDirection.y + pullSpeed * Time.fixedDeltaTime, -1f, 1f);
} else {
InputDirection.y = InputDirection.y - (InputDirection.y * pullSpeed * Time.fixedDeltaTime);
if (Mathf.Abs(InputDirection.y) < 0.025f) {
InputDirection.y = 0;
}
}
if (input1.x < 0) {
InputDirection.x = Mathf.Clamp( InputDirection.x - turnRate * Time.fixedDeltaTime, -1f, 1f);
} else if (input1.x > 0) {
InputDirection.x = Mathf.Clamp( InputDirection.x + turnRate * Time.fixedDeltaTime, -1f, 1f);
} else {
InputDirection.x = InputDirection.x - (InputDirection.x * turnRate * Time.fixedDeltaTime);
if (Mathf.Abs(InputDirection.x) < 0.025f) {
InputDirection.x = 0;
}
}
if (input2.x < 0) {
shipRotation = Mathf.Clamp(shipRotation + shipRotationRate * Time.deltaTime, -1f, 1f);
} else if (input2.x > 0) {
shipRotation = Mathf.Clamp(shipRotation - shipRotationRate * Time.deltaTime, -1f, 1f);
} else {
shipRotation = Mathf.Clamp(shipRotation - shipRotation * shipRotationRate * Time.deltaTime, -1f, 1f);
}
transform.RotateAround(transform.position, transform.right, Time.fixedDeltaTime * InputDirection.y * pitchSpeed);
transform.RotateAround(transform.position, transform.up, Time.fixedDeltaTime * InputDirection.x * turnSpeed);
transform.RotateAround(transform.position, transform.forward, Time.fixedDeltaTime * shipRotation * RotateSpeed);
shipModel.localRotation = Quaternion.Euler(0,180,-shipRotation*maxShipRotation);
Vector3 velNormal = velocity.normalized;
float d2 = (1 - Mathf.Pow(DragEffect, -1f * (velocity.magnitude/MaxSpeed)));
float dampForce = d2 * (acceleration);
Vector3 dragForce = velNormal*dampForce;
dragForce *= dragForceMultiplier;
velocity -= dragForce * Time.fixedDeltaTime;
velocity += accelerationVector * Time.fixedDeltaTime;
controller.Move(velocity * Time.fixedDeltaTime);
Vector3 dird23 = (velocity.magnitude <= 0.5f) ? transform.forward : velocity.normalized;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment