add ckg
plantilla base para movimiento básico
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cec3c6601503804794d4f5a49f6ef9a
|
||||
timeCreated: 1470351553
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/airCraftController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,710 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class boatController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public otherVehicleParts vehicleParts;
|
||||
public vehicleSettings settings;
|
||||
|
||||
[Space]
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float moveForwardSpeedMultiplier;
|
||||
public float moveBackwardSpeedMultiplier;
|
||||
|
||||
public float forwardMovementLerpSpeed = 0.8f;
|
||||
|
||||
public float airControlAmount;
|
||||
public float airControlRotationAmount = 4;
|
||||
public float brakeForce = 5;
|
||||
|
||||
public float rollRotationSpeed = 5;
|
||||
|
||||
public bool rollRotationReversed;
|
||||
|
||||
public float rotationExtraForwardMovement = 0.4f;
|
||||
|
||||
public float rotationLerpSpeed = 0.6f;
|
||||
|
||||
[Space]
|
||||
[Header ("Density Settings")]
|
||||
[Space]
|
||||
|
||||
public bool changeDensityEnabled = true;
|
||||
|
||||
public float densityChangeAmount = 0.05f;
|
||||
|
||||
public Vector2 densityClampValues;
|
||||
|
||||
[Space]
|
||||
[Header ("Orientation Settings")]
|
||||
[Space]
|
||||
|
||||
public float maxAngleRangeForProperOrientationForces = 45;
|
||||
|
||||
public bool autoOrientateUpOnWater;
|
||||
public float minAngleToAutoOrientateUpOnWater;
|
||||
public float autoOrientateUpForceAmountOnWater;
|
||||
|
||||
public bool autoOrientateUpOnAir;
|
||||
public float minAngleToAutoOrientateUpOnAir;
|
||||
public float autoOrientateUpForceAmountOnAir;
|
||||
|
||||
[Space]
|
||||
[Header ("Wind Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkWindState;
|
||||
|
||||
public bool sailActive;
|
||||
|
||||
public bool ignoreWindForcesIfNotDrivingBoat;
|
||||
|
||||
public bool addWindForceIfSailNotActive;
|
||||
|
||||
public float windForceMultiplierIfSailNotActive = 0.5f;
|
||||
|
||||
public Transform sailTransform;
|
||||
|
||||
public Transform sailDirectionTransform;
|
||||
|
||||
public float sailWindSpeedMultiplier;
|
||||
|
||||
public float sailRotationSpeed;
|
||||
|
||||
public float sailRotationClamp;
|
||||
public float sailRotationAmount;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool checkBoatOrientationOnWind;
|
||||
|
||||
public float maxAngleToReduceSpeedOnIncorrectWindDirection;
|
||||
|
||||
public float reduceSpeedOnIncorrectWindDirectionMultiplier;
|
||||
|
||||
public bool showWindDirectionObject;
|
||||
|
||||
public float windDirectionRotationSpeed;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnActiveWindDetection;
|
||||
public UnityEvent eventOnDeactiveWindDetection;
|
||||
|
||||
public UnityEvent eventOnActiveSail;
|
||||
public UnityEvent eventOnDeactiveSail;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool anyOnGround;
|
||||
|
||||
public float normalAngle;
|
||||
|
||||
public bool properlyOrientedUp;
|
||||
|
||||
public float windAirSpeedMultiplier;
|
||||
|
||||
public float windAngle;
|
||||
|
||||
public float regularWindAngle;
|
||||
|
||||
public bool sailLookingRight;
|
||||
|
||||
public Vector3 forceToApply;
|
||||
|
||||
public float reducedSpeedOnIncorrectWindMultiplier;
|
||||
|
||||
public float boatAngleWithWind;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public objectOnWater mainObjectOnWater;
|
||||
|
||||
public Transform externalRotationForcePointTransform;
|
||||
|
||||
public windOnObjectState mainWindOnObjectState;
|
||||
|
||||
public Transform windDirectionTransform;
|
||||
|
||||
|
||||
float originalJumpPower;
|
||||
Vector3 moveInput;
|
||||
|
||||
Transform vehicleCameraTransform;
|
||||
|
||||
float rotationToApply;
|
||||
|
||||
bool desiredJump;
|
||||
|
||||
Vector3 externalRotationForcePoint;
|
||||
|
||||
Vector3 totalForceToApply;
|
||||
|
||||
float totalRotationToApply;
|
||||
|
||||
float forwardInput;
|
||||
|
||||
float currentSteeringWheelZAxisAngle;
|
||||
|
||||
float currentSailYAxisAngle;
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
}
|
||||
|
||||
public override void Start ()
|
||||
{
|
||||
base.Start ();
|
||||
|
||||
originalJumpPower = vehicleControllerSettings.jumpPower;
|
||||
|
||||
vehicleCameraTransform = mainVehicleCameraController.transform;
|
||||
|
||||
setWindCheckState (checkWindState);
|
||||
|
||||
setSailActiveState (sailActive);
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
base.vehicleUpdate ();
|
||||
|
||||
forwardInput = motorInput;
|
||||
|
||||
if (!checkWindState) {
|
||||
if (rotationToApply != 0) {
|
||||
if (forwardInput == 0) {
|
||||
forwardInput = rotationExtraForwardMovement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
moveInput = forwardInput * transform.forward;
|
||||
//+ horizontalAxis * vehicleCameraTransform.right;
|
||||
|
||||
moveInput = Vector3.ClampMagnitude (moveInput, 1f);
|
||||
|
||||
if (vehicleParts.SteeringWheel != null) {
|
||||
currentSteeringWheelZAxisAngle =
|
||||
Mathf.Lerp (currentSteeringWheelZAxisAngle, -vehicleParts.steerAngleLimit * horizontalAxis, Time.deltaTime * vehicleParts.steerRotationSpeed);
|
||||
|
||||
if (Mathf.Abs (currentSteeringWheelZAxisAngle) > 0.01f) {
|
||||
|
||||
vehicleParts.SteeringWheel.localEulerAngles =
|
||||
new Vector3 (vehicleParts.SteeringWheel.localEulerAngles.x, vehicleParts.SteeringWheel.localEulerAngles.y, currentSteeringWheelZAxisAngle);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkWindState) {
|
||||
if (Mathf.Abs (rawAxisValues.y) > 0) {
|
||||
if (rawAxisValues.y > 0) {
|
||||
currentSailYAxisAngle += sailRotationAmount;
|
||||
} else {
|
||||
currentSailYAxisAngle -= sailRotationAmount;
|
||||
}
|
||||
}
|
||||
|
||||
currentSailYAxisAngle = Mathf.Clamp (currentSailYAxisAngle, -sailRotationClamp, sailRotationClamp);
|
||||
|
||||
Vector3 eulerTarget = currentSailYAxisAngle * Vector3.up;
|
||||
|
||||
Quaternion targetRotation = Quaternion.Euler (eulerTarget);
|
||||
|
||||
sailTransform.localRotation = Quaternion.Lerp (sailTransform.localRotation, targetRotation, sailRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (usingHoverBoardWaypoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
fixedUpdateVehicle ();
|
||||
|
||||
if (checkWindState) {
|
||||
bool isWindDetected = mainWindOnObjectState.isWindDetected ();
|
||||
|
||||
Vector3 windDirection = Vector3.up;
|
||||
|
||||
bool canCheckWindForcesResult = true;
|
||||
|
||||
if (ignoreWindForcesIfNotDrivingBoat) {
|
||||
if (!isDrivingActive ()) {
|
||||
canCheckWindForcesResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isWindDetected && canCheckWindForcesResult) {
|
||||
if (sailActive) {
|
||||
windDirection = mainWindOnObjectState.getwindDirection ();
|
||||
|
||||
windAngle = Vector3.SignedAngle (windDirection, sailDirectionTransform.forward, sailDirectionTransform.up);
|
||||
|
||||
sailLookingRight = true;
|
||||
|
||||
float windAngleABS = Mathf.Abs (windAngle);
|
||||
|
||||
// print (sailTransform.localEulerAngles.y);
|
||||
|
||||
if (sailTransform.localEulerAngles.y < 180) {
|
||||
sailLookingRight = false;
|
||||
}
|
||||
|
||||
regularWindAngle = Vector3.Angle (windDirection, sailDirectionTransform.forward);
|
||||
|
||||
if (sailLookingRight) {
|
||||
if (windAngleABS < 90) {
|
||||
windAirSpeedMultiplier = (sailRotationClamp - regularWindAngle) / sailRotationClamp;
|
||||
// print ("right and lower 90");
|
||||
} else {
|
||||
// print ("right and higher 90");
|
||||
|
||||
windAirSpeedMultiplier = (regularWindAngle - sailRotationClamp) / sailRotationClamp;
|
||||
}
|
||||
} else {
|
||||
if (windAngleABS > 90) {
|
||||
windAirSpeedMultiplier = (regularWindAngle - sailRotationClamp) / sailRotationClamp;
|
||||
// print ("left and lower 90");
|
||||
} else {
|
||||
// print ("left and higher 90");
|
||||
|
||||
windAirSpeedMultiplier = (sailRotationClamp - regularWindAngle) / sailRotationClamp;
|
||||
}
|
||||
// windAirSpeedMultiplier = (regularWindAngle - sailRotationClamp) / sailRotationClamp;
|
||||
|
||||
// windAirSpeedMultiplier = 0;
|
||||
}
|
||||
|
||||
|
||||
// windAirSpeedMultiplier = regularWindAngle / sailRotationClamp;
|
||||
|
||||
windAirSpeedMultiplier = Mathf.Clamp (windAirSpeedMultiplier, 0, 1);
|
||||
|
||||
forceToApply = windAirSpeedMultiplier * mainWindOnObjectState.getWindForce () * sailWindSpeedMultiplier * windDirection;
|
||||
|
||||
if (checkBoatOrientationOnWind) {
|
||||
boatAngleWithWind = Vector3.SignedAngle (windDirection, transform.forward, transform.up);
|
||||
|
||||
float boatAngleWithWindABS = Mathf.Abs (boatAngleWithWind);
|
||||
|
||||
if (boatAngleWithWindABS > maxAngleToReduceSpeedOnIncorrectWindDirection) {
|
||||
|
||||
if (boatAngleWithWindABS > 180) {
|
||||
boatAngleWithWindABS -= 180;
|
||||
}
|
||||
|
||||
reducedSpeedOnIncorrectWindMultiplier = (boatAngleWithWindABS / 180) * reduceSpeedOnIncorrectWindDirectionMultiplier;
|
||||
|
||||
forceToApply *= reducedSpeedOnIncorrectWindMultiplier;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (addWindForceIfSailNotActive) {
|
||||
windDirection = mainWindOnObjectState.getwindDirection ();
|
||||
|
||||
forceToApply = mainWindOnObjectState.getWindForce () * windForceMultiplierIfSailNotActive * windDirection;
|
||||
} else {
|
||||
forceToApply = Vector3.zero;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
forceToApply = Vector3.zero;
|
||||
|
||||
}
|
||||
|
||||
if (showWindDirectionObject) {
|
||||
if (sailActive) {
|
||||
Quaternion windDirectionRotationTarget = Quaternion.LookRotation (windDirection);
|
||||
|
||||
windDirectionTransform.rotation = Quaternion.Lerp (windDirectionTransform.rotation, windDirectionRotationTarget, Time.deltaTime * windDirectionRotationSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forwardMovementLerpSpeed > 0) {
|
||||
totalForceToApply = Vector3.Lerp (totalForceToApply, forceToApply, Time.fixedDeltaTime * forwardMovementLerpSpeed);
|
||||
} else {
|
||||
totalForceToApply = forceToApply;
|
||||
}
|
||||
|
||||
mainObjectOnWater.updateExternalForces (totalForceToApply, true);
|
||||
|
||||
if (rotationLerpSpeed > 0) {
|
||||
totalRotationToApply = Mathf.Lerp (totalRotationToApply, rotationToApply, Time.fixedDeltaTime * rotationLerpSpeed);
|
||||
} else {
|
||||
totalRotationToApply = rotationToApply;
|
||||
}
|
||||
|
||||
float currentRotationSpeed = rollRotationSpeed;
|
||||
|
||||
if (!anyOnGround) {
|
||||
currentRotationSpeed = airControlRotationAmount;
|
||||
}
|
||||
|
||||
mainObjectOnWater.updateExternalRotationForces (totalRotationToApply * currentRotationSpeed,
|
||||
vehicleCameraTransform.up, externalRotationForcePoint);
|
||||
|
||||
currentSpeed = totalForceToApply.magnitude;
|
||||
}
|
||||
|
||||
void fixedUpdateVehicle ()
|
||||
{
|
||||
forceToApply = Vector3.zero;
|
||||
|
||||
anyOnGround = mainObjectOnWater.isObjectOnWaterActive ();
|
||||
|
||||
if (!checkWindState) {
|
||||
if (anyOnGround) {
|
||||
if (forwardInput > 0) {
|
||||
forceToApply = moveForwardSpeedMultiplier * moveInput;
|
||||
} else if (forwardInput < 0) {
|
||||
forceToApply = moveBackwardSpeedMultiplier * moveInput;
|
||||
}
|
||||
} else {
|
||||
forceToApply = airControlAmount * moveInput;
|
||||
}
|
||||
}
|
||||
|
||||
normalAngle = Vector3.SignedAngle (transform.up, mainVehicleGravityControl.getCurrentNormal (), transform.forward);
|
||||
|
||||
float normalAngleABS = Mathf.Abs (normalAngle);
|
||||
|
||||
properlyOrientedUp = (normalAngleABS < maxAngleRangeForProperOrientationForces);
|
||||
|
||||
if (anyOnGround) {
|
||||
if (autoOrientateUpOnWater) {
|
||||
if (normalAngleABS > minAngleToAutoOrientateUpOnWater) {
|
||||
float valueMultiplier = 1;
|
||||
|
||||
if (normalAngle > 0) {
|
||||
valueMultiplier = -1;
|
||||
}
|
||||
|
||||
mainRigidbody.AddRelativeForce (0, 0, autoOrientateUpForceAmountOnWater * valueMultiplier);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (autoOrientateUpOnAir) {
|
||||
if (normalAngleABS > minAngleToAutoOrientateUpOnAir) {
|
||||
float valueMultiplier = 1;
|
||||
|
||||
if (normalAngle > 0) {
|
||||
valueMultiplier = -1;
|
||||
}
|
||||
|
||||
mainRigidbody.AddRelativeForce (0, 0, autoOrientateUpForceAmountOnAir * valueMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!properlyOrientedUp) {
|
||||
forceToApply = Vector3.zero;
|
||||
}
|
||||
|
||||
if (anyOnGround && properlyOrientedUp) {
|
||||
if (usingBoost) {
|
||||
forceToApply *= boostInput;
|
||||
}
|
||||
|
||||
if (desiredJump) {
|
||||
desiredJump = false;
|
||||
|
||||
forceToApply += mainRigidbody.mass * vehicleControllerSettings.jumpPower * vehicleCameraTransform.up;
|
||||
}
|
||||
|
||||
bool brakeActive = (braking || isBrakeActive ());
|
||||
|
||||
if (brakeActive) {
|
||||
float verticalVelocity = vehicleCameraTransform.InverseTransformDirection (mainRigidbody.linearVelocity).y;
|
||||
Vector3 downVelocity = verticalVelocity * vehicleCameraTransform.up;
|
||||
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, Vector3.zero + downVelocity, Time.deltaTime * brakeForce);
|
||||
}
|
||||
}
|
||||
|
||||
if (properlyOrientedUp) {
|
||||
if (rollRotationReversed) {
|
||||
rotationToApply = horizontalAxis;
|
||||
} else {
|
||||
rotationToApply = -horizontalAxis;
|
||||
}
|
||||
} else {
|
||||
rotationToApply = 0;
|
||||
}
|
||||
|
||||
externalRotationForcePoint = externalRotationForcePointTransform.position;
|
||||
}
|
||||
|
||||
public void checkEventOnWindStateChange (bool state)
|
||||
{
|
||||
if (state) {
|
||||
eventOnActiveWindDetection.Invoke ();
|
||||
} else {
|
||||
eventOnDeactiveWindDetection.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkEventOnSailStateChange (bool state)
|
||||
{
|
||||
if (state) {
|
||||
eventOnActiveSail.Invoke ();
|
||||
} else {
|
||||
eventOnDeactiveSail.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateMovingState ()
|
||||
{
|
||||
moving = verticalAxis != 0 || horizontalAxis != 0;
|
||||
}
|
||||
|
||||
public override bool isVehicleOnGround ()
|
||||
{
|
||||
return anyOnGround;
|
||||
}
|
||||
|
||||
//if the vehicle is using the gravity control, set the state in this component
|
||||
public override void changeGravityControlUse (bool state)
|
||||
{
|
||||
base.changeGravityControlUse (state);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
base.changeVehicleState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void setTurnOnState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void setTurnOffState (bool previouslyTurnedOn)
|
||||
{
|
||||
base.setTurnOffState (previouslyTurnedOn);
|
||||
|
||||
if (previouslyTurnedOn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override bool isDrivingActive ()
|
||||
{
|
||||
return driving;
|
||||
}
|
||||
|
||||
public override void setEngineOnOrOffState ()
|
||||
{
|
||||
base.setEngineOnOrOffState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
{
|
||||
base.turnOnOrOff (state, previouslyTurnedOn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
base.disableVehicle ();
|
||||
|
||||
}
|
||||
|
||||
//if the vehicle is using the boost, set the boost particles
|
||||
public override void usingBoosting ()
|
||||
{
|
||||
base.usingBoosting ();
|
||||
|
||||
}
|
||||
|
||||
//use a jump platform
|
||||
public void useVehicleJumpPlatform (Vector3 direction)
|
||||
{
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * direction, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public void useJumpPlatformParable (Vector3 direction)
|
||||
{
|
||||
Vector3 jumpForce = direction;
|
||||
|
||||
mainRigidbody.AddForce (jumpForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
public void setNewJumpPower (float newJumpPower)
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = newJumpPower * 100;
|
||||
}
|
||||
|
||||
public void setOriginalJumpPower ()
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = originalJumpPower;
|
||||
}
|
||||
|
||||
public void setCanJumpState (bool state)
|
||||
{
|
||||
vehicleControllerSettings.canJump = state;
|
||||
}
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public override void inputJump ()
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && vehicleControllerSettings.canJump) {
|
||||
if (usingHoverBoardWaypoint) {
|
||||
pickOrReleaseHoverboardVehicle (false, false);
|
||||
|
||||
Vector3 totalJumpForce = mainRigidbody.mass * hoverboardJumpForce * (currentNormal + transform.forward);
|
||||
|
||||
if (useHoverboardJumpClamp) {
|
||||
totalJumpForce = Vector3.ClampMagnitude (totalJumpForce, hoverboardJumpClamp);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalJumpForce, ForceMode.Impulse);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (anyOnGround) {
|
||||
desiredJump = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseTurbo (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && !usingHoverBoardWaypoint) {
|
||||
//boost input
|
||||
if (holdingButton) {
|
||||
if (vehicleControllerSettings.canUseBoost) {
|
||||
usingBoost = true;
|
||||
//set the camera move away action
|
||||
mainVehicleCameraController.usingBoost (true, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
}
|
||||
} else {
|
||||
//stop boost input
|
||||
usingBoost = false;
|
||||
|
||||
//disable the camera move away action
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
|
||||
usingBoosting ();
|
||||
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseBrake (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && anyOnGround) {
|
||||
braking = holdingButton;
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputSetTurnOnState ()
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
if (mainVehicleHUDManager.canSetTurnOnState) {
|
||||
setEngineOnOrOffState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSailActiveState (bool state)
|
||||
{
|
||||
sailActive = state;
|
||||
|
||||
checkEventOnSailStateChange (sailActive);
|
||||
}
|
||||
|
||||
public void setWindCheckState (bool state)
|
||||
{
|
||||
checkWindState = state;
|
||||
|
||||
checkEventOnWindStateChange (checkWindState);
|
||||
}
|
||||
|
||||
public void inputToggleWindCheckState ()
|
||||
{
|
||||
if (driving) {
|
||||
setWindCheckState (!checkWindState);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputToggleSailActive ()
|
||||
{
|
||||
if (driving) {
|
||||
setSailActiveState (!sailActive);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputIncreaseDensity ()
|
||||
{
|
||||
if (driving) {
|
||||
if (changeDensityEnabled) {
|
||||
if (mainObjectOnWater.getDensity () < densityClampValues.y) {
|
||||
mainObjectOnWater.addOrRemoveDensity (densityChangeAmount);
|
||||
} else {
|
||||
mainObjectOnWater.setNewDensity (densityClampValues.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputDecreaseDensity ()
|
||||
{
|
||||
if (driving) {
|
||||
if (changeDensityEnabled) {
|
||||
if (mainObjectOnWater.getDensity () > densityClampValues.x) {
|
||||
mainObjectOnWater.addOrRemoveDensity (-densityChangeAmount);
|
||||
} else {
|
||||
mainObjectOnWater.setNewDensity (densityClampValues.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class otherVehicleParts
|
||||
{
|
||||
public Transform COM;
|
||||
public GameObject chassis;
|
||||
|
||||
public Transform SteeringWheel;
|
||||
|
||||
public float steerAngleLimit;
|
||||
|
||||
public float steerRotationSpeed;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehicleSettings
|
||||
{
|
||||
public LayerMask layer;
|
||||
public GameObject vehicleCamera;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be1d78afc7444b548a9ab7389f5fe36c
|
||||
timeCreated: 1674660744
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/boatController.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 238685913253c0843b2b519c6d7786fb
|
||||
timeCreated: 1461366893
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/carController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dummyVehicleController : vehicleController
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6de0571816083c4a9ed9b5f3f089089
|
||||
timeCreated: 1551942597
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/dummyVehicleController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,421 @@
|
||||
//using UnityEngine;
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//
|
||||
//public class emptyVehicleController : MonoBehaviour
|
||||
//{
|
||||
// public OtherCarParts otherCarParts;
|
||||
// public carSettings settings;
|
||||
//
|
||||
// public float currentSpeed;
|
||||
//
|
||||
// public bool anyOnGround;
|
||||
//
|
||||
// bool driving;
|
||||
// bool jump;
|
||||
// bool colliding;
|
||||
// bool moving;
|
||||
// bool usingBoost;
|
||||
// bool vehicleDestroyed;
|
||||
// bool usingGravityControl;
|
||||
//
|
||||
// float resetTimer = 0;
|
||||
// float motorInput = 0;
|
||||
// float steerInput = 0;
|
||||
// float boostInput = 1;
|
||||
//
|
||||
// float horizontalAxis;
|
||||
// float verticalAxis;
|
||||
// float originalJumpPower;
|
||||
// RaycastHit hit;
|
||||
// Vector3 normal;
|
||||
// Rigidbody mainRigidbody;
|
||||
// vehicleCameraController vCamera;
|
||||
// vehicleHUDManager hudManager;
|
||||
// inputActionManager actionManager;
|
||||
// vehicleGravityControl vehicleGravityControlManager;
|
||||
// shipInterfaceInfo interfaceInfo;
|
||||
// bool isTurnedOn;
|
||||
//
|
||||
// Vector2 axisValues;
|
||||
// public bool usingImpulse;
|
||||
// float lastTimeImpulseUsed;
|
||||
// float lastTimeJump;
|
||||
//
|
||||
// bool bouncingVehicle;
|
||||
// Coroutine bounceCoroutine;
|
||||
// float collisionForceLimit = 5;
|
||||
//
|
||||
// bool braking;
|
||||
//
|
||||
// void Start ()
|
||||
// {
|
||||
// //set the sound components
|
||||
// setAudioState (otherCarParts.engineAudio, 5, 0, otherCarParts.engineClip, true, false, false);
|
||||
// setAudioState (otherCarParts.engineStartAudio, 5, 0.7f, otherCarParts.engineStartClip, false, false, false);
|
||||
//
|
||||
// //get the vehicle rigidbody
|
||||
// mainRigidbody = GetComponent<Rigidbody> ();
|
||||
//
|
||||
// vCamera = settings.vehicleCamera.GetComponent<vehicleCameraController> ();
|
||||
// hudManager = GetComponent<vehicleHUDManager> ();
|
||||
// originalJumpPower = settings.jumpPower;
|
||||
// vehicleGravityControlManager = GetComponent<vehicleGravityControl> ();
|
||||
//
|
||||
// actionManager = GetComponentInParent<inputActionManager> ();
|
||||
//
|
||||
// interfaceInfo = GetComponentInChildren<shipInterfaceInfo> ();
|
||||
// }
|
||||
//
|
||||
// void Update ()
|
||||
// {
|
||||
// //if the player is driving this vehicle and the gravity control is not being used, then
|
||||
// if (driving && !usingGravityControl) {
|
||||
// axisValues = actionManager.getPlayerMovementAxis ();
|
||||
// horizontalAxis = axisValues.x;
|
||||
// if (isTurnedOn) {
|
||||
//
|
||||
// //get the current values from the input manager, keyboard and touch controls
|
||||
// verticalAxis = axisValues.y;
|
||||
//
|
||||
// //jump input
|
||||
//// if (settings.canJump && actionManager.getActionInput ("Jump")) {
|
||||
//// jump = true;
|
||||
//// }
|
||||
//
|
||||
// //boost input
|
||||
//// if (settings.canUseBoost && actionManager.getActionInput ("Enable Turbo")) {
|
||||
//// usingBoost = true;
|
||||
//// //set the camera move away action
|
||||
//// vCamera.usingBoost (true, "Boost");
|
||||
//// }
|
||||
//
|
||||
// //stop boost input
|
||||
//// if (actionManager.getActionInput ("Disable Turbo")) {
|
||||
//// usingBoost = false;
|
||||
//// //disable the camera move away action
|
||||
//// vCamera.usingBoost (false, "Boost");
|
||||
//// //disable the boost particles
|
||||
//// boostInput = 1;
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// //if the boost input is enabled, check if there is energy enough to use it
|
||||
// if (usingBoost) {
|
||||
// //if there is enough energy, enable the boost
|
||||
// if (hudManager.useBoost (moving)) {
|
||||
// boostInput = settings.maxBoostMultiplier;
|
||||
// }
|
||||
//
|
||||
// //else, disable the boost
|
||||
// else {
|
||||
// usingBoost = false;
|
||||
// //if the vehicle is not using the gravity control system, disable the camera move away action
|
||||
// if (!vehicleGravityControlManager.isGravityPowerActive ()) {
|
||||
// vCamera.usingBoost (false, "Boost");
|
||||
// }
|
||||
// boostInput = 1;
|
||||
// }
|
||||
// }
|
||||
//// if (hudManager.canSetTurnOnState && actionManager.getActionInput ("Set TurnOn State")) {
|
||||
//// setEngineOnOrOffState ();
|
||||
//// }
|
||||
////
|
||||
//// if (actionManager.getActionInput ("Horn")) {
|
||||
//// pressHorn ();
|
||||
//// }
|
||||
////
|
||||
//// if (actionManager.getActionInput ("Brake")) {
|
||||
//// braking = true;
|
||||
//// } else {
|
||||
//// braking = false;
|
||||
//// }
|
||||
//
|
||||
// //set the current speed in the HUD of the vehicle
|
||||
// hudManager.getSpeed (currentSpeed, settings.maxForwardSpeed);
|
||||
// } else {
|
||||
// //else, set the input values to 0
|
||||
// horizontalAxis = 0;
|
||||
// verticalAxis = 0;
|
||||
// }
|
||||
//
|
||||
// if (hudManager.usedByAI) {
|
||||
// horizontalAxis = vehicleAI.steering;
|
||||
// verticalAxis = vehicleAI.accel;
|
||||
// //print (verticalAxis);
|
||||
// //braking = vehicleAI.footbrake == 1 ? true : false;
|
||||
// }
|
||||
//
|
||||
// //set the current axis input in the motor input
|
||||
// motorInput = verticalAxis;
|
||||
// moving = verticalAxis != 0;
|
||||
//
|
||||
// //if the vehicle has fuel, allow to move it
|
||||
// if (moving) {
|
||||
// if (!hudManager.useFuel ()) {
|
||||
// motorInput = 0;
|
||||
// if (isTurnedOn) {
|
||||
// turnOnOrOff (false, isTurnedOn);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void setEngineOnOrOffState ()
|
||||
// {
|
||||
// if (hudManager.hasFuel ()) {
|
||||
// turnOnOrOff (!isTurnedOn, isTurnedOn);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void pressHorn ()
|
||||
// {
|
||||
// setAudioState (otherCarParts.hornAudio, 5, 1, otherCarParts.hornClip, false, true, false);
|
||||
// hudManager.activateHorn ();
|
||||
// }
|
||||
//
|
||||
// void FixedUpdate ()
|
||||
// {
|
||||
// //allows vehicle to remain roughly pointing in the direction of travel
|
||||
// //if the vehicle is not on the ground, not colliding, rotating and its speed is higher that 5
|
||||
// if (!anyOnGround && settings.preserveDirectionWhileInAir && !colliding && currentSpeed > 5) {
|
||||
// //check the time to stabilize
|
||||
// //rotate every axis of the vehicle in the rigidbody velocity direction
|
||||
// mainRigidbody.freezeRotation = true;
|
||||
// float angleX = Mathf.Asin (transform.InverseTransformDirection (Vector3.Cross (normal.normalized, transform.up)).x) * Mathf.Rad2Deg;
|
||||
// float angleZ = Mathf.Asin (transform.InverseTransformDirection (Vector3.Cross (normal.normalized, transform.up)).z) * Mathf.Rad2Deg;
|
||||
// float angleY = Mathf.Asin (transform.InverseTransformDirection (Vector3.Cross (mainRigidbody.velocity.normalized, transform.forward)).y) * Mathf.Rad2Deg;
|
||||
// transform.Rotate (new Vector3 (angleX, angleY, angleZ) * Time.deltaTime * (-1));
|
||||
// }
|
||||
//
|
||||
// //if any of the vehicle is on the groud, free the rigidbody rotation
|
||||
// if (anyOnGround) {
|
||||
// mainRigidbody.freezeRotation = false;
|
||||
// }
|
||||
//
|
||||
// //get the current speed value
|
||||
// currentSpeed = mainRigidbody.velocity.magnitude * 3;
|
||||
// //calculate the current acceleration
|
||||
//
|
||||
// if (interfaceInfo) {
|
||||
// interfaceInfo.shipEnginesState (isTurnedOn);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// //if the vehicle is using the gravity control, set the state in this component
|
||||
// public void changeGravityControlUse (bool state)
|
||||
// {
|
||||
// usingGravityControl = state;
|
||||
//
|
||||
// usingImpulse = false;
|
||||
// }
|
||||
//
|
||||
// //the player is getting on or off from the vehicle, so
|
||||
// //public void changeVehicleState (Vector3 nextPlayerPos)
|
||||
// public void changeVehicleState ()
|
||||
// {
|
||||
// driving = !driving;
|
||||
// //set the audio values if the player is getting on or off from the vehicle
|
||||
// if (driving) {
|
||||
// if (hudManager.autoTurnOnWhenGetOn) {
|
||||
// turnOnOrOff (true, isTurnedOn);
|
||||
// }
|
||||
// } else {
|
||||
// turnOnOrOff (false, isTurnedOn);
|
||||
// }
|
||||
//
|
||||
// //set the same state in the gravity control components
|
||||
// vehicleGravityControlManager.changeGravityControlState (driving);
|
||||
//
|
||||
// if (interfaceInfo) {
|
||||
// interfaceInfo.enableOrDisableInterface (driving);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void setTurnOnState ()
|
||||
// {
|
||||
// setAudioState (otherCarParts.engineAudio, 5, 0, otherCarParts.engineClip, true, true, false);
|
||||
// setAudioState (otherCarParts.engineStartAudio, 5, 0.7f, otherCarParts.engineStartClip, false, true, false);
|
||||
// }
|
||||
//
|
||||
// public void setTurnOffState (bool previouslyTurnedOn)
|
||||
// {
|
||||
// if (previouslyTurnedOn) {
|
||||
// setAudioState (otherCarParts.engineAudio, 5, 0, otherCarParts.engineClip, false, false, true);
|
||||
// setAudioState (otherCarParts.engineAudio, 5, 1, otherCarParts.engineEndClip, false, true, false);
|
||||
// }
|
||||
// motorInput = 0;
|
||||
// steerInput = 0;
|
||||
// boostInput = 1;
|
||||
// horizontalAxis = 0;
|
||||
// verticalAxis = 0;
|
||||
//
|
||||
// //stop the boost
|
||||
// if (usingBoost) {
|
||||
// usingBoost = false;
|
||||
// vCamera.usingBoost (false, "Boost");
|
||||
//
|
||||
// }
|
||||
// usingImpulse = false;
|
||||
// }
|
||||
//
|
||||
// public void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
// {
|
||||
// isTurnedOn = state;
|
||||
// if (isTurnedOn) {
|
||||
// setTurnOnState ();
|
||||
// } else {
|
||||
// setTurnOffState (previouslyTurnedOn);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //the vehicle has been destroyed, so disabled every component in it
|
||||
// public void disableVehicle ()
|
||||
// {
|
||||
// //stop the audio sources
|
||||
// setAudioState (otherCarParts.engineAudio, 5, 0, otherCarParts.engineClip, false, false, false);
|
||||
// setAudioState (otherCarParts.engineStartAudio, 5, 0.7f, otherCarParts.engineStartClip, false, false, false);
|
||||
// vehicleDestroyed = true;
|
||||
//
|
||||
// setTurnOffState (false);
|
||||
//
|
||||
// //disable the controller
|
||||
// //GetComponent<carController> ().enabled = false;
|
||||
//
|
||||
// if (interfaceInfo) {
|
||||
// interfaceInfo.enableOrDisableInterface (false);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //get the current normal in the gravity control component
|
||||
// public void setNormal (Vector3 normalValue)
|
||||
// {
|
||||
// normal = normalValue;
|
||||
// }
|
||||
//
|
||||
// //play or stop every audio component in the vehicle, like engine, skid, etc.., configuring also volume and loop according to the movement of the vehicle
|
||||
// public void setAudioState (AudioSource source, float distance, float volume, AudioClip audioClip, bool loop, bool play, bool stop)
|
||||
// {
|
||||
// source.minDistance = distance;
|
||||
// source.volume = volume;
|
||||
// source.clip = audioClip;
|
||||
// source.loop = loop;
|
||||
// source.spatialBlend = 1;
|
||||
// if (play) {
|
||||
// source.Play ();
|
||||
// }
|
||||
// if (stop) {
|
||||
// source.Stop ();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //if any collider in the vehicle collides, then
|
||||
// void OnCollisionEnter (Collision collision)
|
||||
// {
|
||||
// //check that the collision is not with the player
|
||||
// if (collision.contacts.Length > 0 && collision.gameObject.tag != "Player") {
|
||||
// //if the velocity of the collision is higher that the limit
|
||||
// if (collision.relativeVelocity.magnitude > collisionForceLimit) {
|
||||
// //set the collision audio with a random collision clip
|
||||
// if (otherCarParts.crashClips.Length > 0) {
|
||||
// setAudioState (otherCarParts.crashAudio, 5, 1, otherCarParts.crashClips [UnityEngine.Random.Range (0, otherCarParts.crashClips.Length)], false, true, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //reset the collision values
|
||||
// mainRigidbody.freezeRotation = false;
|
||||
// colliding = true;
|
||||
// }
|
||||
//
|
||||
// //if the vehicle is colliding, then
|
||||
// void OnCollisionStay (Collision collision)
|
||||
// {
|
||||
// //set the values to avoid stabilize the vehicle yet
|
||||
// mainRigidbody.freezeRotation = false;
|
||||
// colliding = true;
|
||||
// }
|
||||
//
|
||||
// //the vehicle is not colliding
|
||||
// void OnCollisionExit (Collision collision)
|
||||
// {
|
||||
// colliding = false;
|
||||
// }
|
||||
//
|
||||
// //use a jump platform
|
||||
// public void useVehicleJumpPlatform (Vector3 direction)
|
||||
// {
|
||||
// mainRigidbody.AddForce (mainRigidbody.mass * direction, ForceMode.Impulse);
|
||||
// }
|
||||
//
|
||||
// public void useJumpPlatformParable (Vector3 direction)
|
||||
// {
|
||||
// Vector3 jumpForce = direction;
|
||||
// print (jumpForce);
|
||||
// mainRigidbody.AddForce (jumpForce, ForceMode.VelocityChange);
|
||||
// }
|
||||
//
|
||||
// public void setJumpPower (float newJumpPower)
|
||||
// {
|
||||
// settings.jumpPower = newJumpPower;
|
||||
// }
|
||||
//
|
||||
// public void setNewJumpPower (float newJumpPower)
|
||||
// {
|
||||
// settings.jumpPower = newJumpPower * 100;
|
||||
// }
|
||||
//
|
||||
// public void setOriginalJumpPower ()
|
||||
// {
|
||||
// settings.jumpPower = originalJumpPower;
|
||||
// }
|
||||
//
|
||||
// public void setMaxSpeed (float maxSpeedValue)
|
||||
// {
|
||||
// settings.maxForwardSpeed = maxSpeedValue;
|
||||
// }
|
||||
//
|
||||
// public void setMaxTurboPower (float maxTurboPower)
|
||||
// {
|
||||
// settings.maxBoostMultiplier = maxTurboPower;
|
||||
// }
|
||||
//
|
||||
// vehicleAINavMesh.movementInfo vehicleAI;
|
||||
//
|
||||
// public void Move (vehicleAINavMesh.movementInfo AI)
|
||||
// {
|
||||
// vehicleAI = AI;
|
||||
// }
|
||||
//
|
||||
// [System.Serializable]
|
||||
// public class OtherCarParts
|
||||
// {
|
||||
// public Transform COM;
|
||||
// public GameObject chassis;
|
||||
// public AudioClip engineStartClip;
|
||||
// public AudioClip engineClip;
|
||||
// public AudioClip engineEndClip;
|
||||
// public AudioClip[] crashClips;
|
||||
// public AudioClip hornClip;
|
||||
// public AudioSource engineStartAudio;
|
||||
// public AudioSource engineAudio;
|
||||
// public AudioSource crashAudio;
|
||||
// public AudioSource hornAudio;
|
||||
// }
|
||||
//
|
||||
// [System.Serializable]
|
||||
// public class carSettings
|
||||
// {
|
||||
// public LayerMask layer;
|
||||
//
|
||||
// public float maxForwardSpeed;
|
||||
// public float maxBackWardSpeed;
|
||||
// public float maxBoostMultiplier;
|
||||
// public GameObject vehicleCamera;
|
||||
// public bool preserveDirectionWhileInAir;
|
||||
// public float jumpPower;
|
||||
// public bool canJump;
|
||||
// public bool canUseBoost;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d62013832f03f144fa5c2148c105e499
|
||||
timeCreated: 1524717024
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/emptyVehicleController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,888 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class flyingController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public float timeToFlip = 2;
|
||||
public float audioEngineSpeed;
|
||||
public float engineMinVolume = 0.5f;
|
||||
public float engineMaxVolume = 1;
|
||||
public float minAudioPitch = 0.5f;
|
||||
public float maxAudioPitch = 1.2f;
|
||||
|
||||
public float maxSpeed = 30;
|
||||
|
||||
public float velocityChangeSpeed = 10;
|
||||
|
||||
public float stabilityForce = 2;
|
||||
public float stabilitySpeed = 2;
|
||||
|
||||
public float forwardSpeed = 15;
|
||||
public float rightSpeed = 15;
|
||||
public float upSpeed = 15;
|
||||
|
||||
public float rollRotationSpeed = 5;
|
||||
|
||||
public float engineArmRotationAmountForward;
|
||||
public float engineArmRotationAmountRight;
|
||||
|
||||
public float engineArmExtraRotationAmount;
|
||||
|
||||
public float engineArmRotationSpeed;
|
||||
|
||||
public float engineRotationSpeed = 10;
|
||||
|
||||
public float groundRaycastDistance;
|
||||
public float hoverForce = 5;
|
||||
public float hoverFoeceOnAir = 2;
|
||||
public float rotateForce = 5;
|
||||
public float extraHoverSpeed = 2;
|
||||
|
||||
public bool increaseHeightIfSurfaceBelowFound;
|
||||
public float raycastDistanceToCheckSurfaceBelow = 5;
|
||||
public float minDistanceToIncreaseHeight = 4;
|
||||
public Transform surfaceBelowRaycastPosition;
|
||||
|
||||
[Space]
|
||||
[Header ("Vehicle Settings")]
|
||||
[Space]
|
||||
|
||||
public otherVehicleParts otherCarParts;
|
||||
public vehicletSettings settings;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public float heightInput;
|
||||
public float rollDirection;
|
||||
public bool groundFound;
|
||||
|
||||
public Vector3 newVelocity;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform leftEngineTransform;
|
||||
public Transform rightEngineTransform;
|
||||
|
||||
public Transform leftEngineArmTransform;
|
||||
public Transform rightEngineArmTransform;
|
||||
|
||||
public Transform groundRaycastPosition;
|
||||
|
||||
float audioPower = 0;
|
||||
float maxEnginePower;
|
||||
|
||||
float resetTimer;
|
||||
|
||||
float steerInput;
|
||||
float forwardInput;
|
||||
|
||||
int i;
|
||||
int collisionForceLimit = 5;
|
||||
|
||||
bool rotating;
|
||||
Transform vehicleCameraTransform;
|
||||
|
||||
float leftInput = 0;
|
||||
float rightInput = 0;
|
||||
|
||||
|
||||
bool checkVehicleTurnedOn;
|
||||
|
||||
Vector3 currenLeftEngineArmRotation;
|
||||
Vector3 currenRightEngineArmRotation;
|
||||
|
||||
Vector3 currenLeftEngineRotation;
|
||||
Vector3 currenRightEngineRotation;
|
||||
|
||||
Vector3 appliedHoverForce;
|
||||
RaycastHit hit;
|
||||
|
||||
bool usingRollInput;
|
||||
|
||||
float currentHitDistance;
|
||||
|
||||
bool surfaceDetected;
|
||||
|
||||
bool increasingHeightFromSurfaceDetected;
|
||||
|
||||
protected override void InitializeAudioElements ()
|
||||
{
|
||||
otherCarParts.InitializeAudioElements ();
|
||||
}
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
|
||||
}
|
||||
|
||||
public override void Start ()
|
||||
{
|
||||
base.Start ();
|
||||
|
||||
//get the boost particles inside the vehicle
|
||||
for (i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
otherCarParts.boostingParticles [i].gameObject.SetActive (false);
|
||||
}
|
||||
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, false, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, false, false);
|
||||
|
||||
vehicleCameraTransform = mainVehicleCameraController.transform;
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
checkCameraType ();
|
||||
|
||||
//if the player is driving this vehicle and the gravity control is not being used, then
|
||||
if (driving && !usingGravityControl) {
|
||||
axisValues = mainInputActionManager.getPlayerMovementAxis ();
|
||||
|
||||
if (vehicleControllerSettings.canUseBoostWithoutVerticalInput) {
|
||||
if (usingBoost) {
|
||||
axisValues.y = 1;
|
||||
}
|
||||
}
|
||||
|
||||
horizontalAxis = axisValues.x;
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
horizontalAxis = 0;
|
||||
}
|
||||
|
||||
rawAxisValues = mainInputActionManager.getPlayerRawMovementAxis ();
|
||||
|
||||
if (vehicleControllerSettings.canUseBoostWithoutVerticalInput) {
|
||||
if (usingBoost) {
|
||||
rawAxisValues.y = 1;
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
rawAxisValues.x = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!useHorizontalInputLerp && !touchPlatform) {
|
||||
horizontalAxis = rawAxisValues.x;
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
horizontalAxis = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainVehicleHUDManager.usedByAI) {
|
||||
rollDirection = horizontalAxis;
|
||||
|
||||
horizontalAxis = 0;
|
||||
}
|
||||
|
||||
if (mainVehicleCameraController.currentState.useCameraSteer && !usingRollInput) {
|
||||
localLook = transform.InverseTransformDirection (mainVehicleCameraController.getLookDirection ());
|
||||
|
||||
if (localLook.z < 0f) {
|
||||
localLook.x = Mathf.Sign (localLook.x);
|
||||
}
|
||||
|
||||
steering = localLook.x;
|
||||
steering = Mathf.Clamp (steering, -1f, 1f);
|
||||
|
||||
steering = -steering;
|
||||
|
||||
rollDirection = steering;
|
||||
}
|
||||
|
||||
if (isTurnedOn) {
|
||||
//get the current values from the input manager, keyboard and touch controls
|
||||
verticalAxis = axisValues.y;
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
verticalAxis = axisValues.x;
|
||||
}
|
||||
}
|
||||
|
||||
//if the boost input is enabled, check if there is energy enough to use it
|
||||
if (usingBoost) {
|
||||
updateMovingState ();
|
||||
|
||||
//if there is enough energy, enable the boost
|
||||
if (mainVehicleHUDManager.useBoost (moving)) {
|
||||
boostInput = vehicleControllerSettings.maxBoostMultiplier;
|
||||
|
||||
usingBoosting ();
|
||||
}
|
||||
//else, disable the boost
|
||||
else {
|
||||
usingBoost = false;
|
||||
//if the vehicle is not using the gravity control system, disable the camera move away action
|
||||
if (!mainVehicleGravityControl.isGravityPowerActive ()) {
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
}
|
||||
|
||||
usingBoosting ();
|
||||
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//set the current speed in the HUD of the vehicle
|
||||
mainVehicleHUDManager.getSpeed (currentSpeed, maxSpeed);
|
||||
|
||||
mainIKDrivingSystem.setNewAngularDirection (verticalAxis * Vector3.forward +
|
||||
horizontalAxis * Vector3.right +
|
||||
heightInput * Vector3.forward +
|
||||
rollDirection * Vector3.up);
|
||||
} else {
|
||||
//else, set the input values to 0
|
||||
horizontalAxis = 0;
|
||||
verticalAxis = 0;
|
||||
|
||||
rawAxisValues = Vector2.zero;
|
||||
}
|
||||
|
||||
updateMovingState ();
|
||||
|
||||
motorInput = verticalAxis;
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
if (motorInput < -0.01f) {
|
||||
motorInput *= (-1);
|
||||
}
|
||||
}
|
||||
|
||||
//if the vehicle has fuel, allow to move it
|
||||
if (moving) {
|
||||
if (!mainVehicleHUDManager.useFuel ()) {
|
||||
motorInput = 0;
|
||||
|
||||
if (isTurnedOn) {
|
||||
turnOnOrOff (false, isTurnedOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerMovingOn3dWorld) {
|
||||
update2_5DState ();
|
||||
}
|
||||
|
||||
updateVehicleControllerState ();
|
||||
}
|
||||
|
||||
void updateVehicleControllerState ()
|
||||
{
|
||||
maxEnginePower = currentSpeed;
|
||||
|
||||
audioPower = Mathf.Lerp (maxEnginePower, motorInput, audioEngineSpeed);
|
||||
otherCarParts.engineAudio.volume = Mathf.Lerp (engineMinVolume, engineMaxVolume, audioPower);
|
||||
otherCarParts.engineAudio.pitch = Mathf.Lerp (minAudioPitch, maxAudioPitch, audioPower);
|
||||
|
||||
if (Mathf.Abs (horizontalAxis) > 0.05f) {
|
||||
steerInput = Mathf.Lerp (steerInput, horizontalAxis, Time.deltaTime * 10);
|
||||
} else {
|
||||
steerInput = Mathf.Lerp (steerInput, horizontalAxis, Time.deltaTime * 10);
|
||||
}
|
||||
if (Mathf.Abs (motorInput) > 0.05f) {
|
||||
forwardInput = Mathf.Lerp (forwardInput, motorInput, Time.deltaTime * 10);
|
||||
} else {
|
||||
forwardInput = Mathf.Lerp (forwardInput, motorInput, Time.deltaTime * 10);
|
||||
}
|
||||
|
||||
float left = 0;
|
||||
float right = 0;
|
||||
|
||||
if ((forwardInput > 0.05f || forwardInput < -0.05f) && (steerInput < 0.05f && steerInput > -0.05f)) {
|
||||
left = right = forwardInput;
|
||||
//print("moving forward or backward");
|
||||
} else if (forwardInput > 0.05f && steerInput > 0) {
|
||||
left = forwardInput;
|
||||
right = -steerInput;
|
||||
//print("moving forward and to the right");
|
||||
} else if (forwardInput > 0.05f && steerInput < 0) {
|
||||
left = steerInput;
|
||||
right = forwardInput;
|
||||
//print("moving forward and to the left");
|
||||
} else if ((forwardInput < 0.05f && forwardInput > -0.05f) && steerInput > 0) {
|
||||
left = 0;
|
||||
right = steerInput;
|
||||
//print("moving to the right");
|
||||
} else if ((forwardInput < 0.05f && forwardInput > -0.05f) && steerInput < 0) {
|
||||
left = -steerInput;
|
||||
right = 0;
|
||||
//print("moving to the left");
|
||||
} else if (forwardInput < -0.05f && steerInput > 0) {
|
||||
left = 0;
|
||||
right = -steerInput;
|
||||
//print("moving backward and to the right");
|
||||
} else if (forwardInput < -0.05f && steerInput < 0) {
|
||||
left = steerInput;
|
||||
right = 0;
|
||||
//print("moving backward and to the left");
|
||||
}
|
||||
|
||||
leftInput = Mathf.Lerp (leftInput, left, Time.deltaTime * 10);
|
||||
rightInput = Mathf.Lerp (rightInput, right, Time.deltaTime * 10);
|
||||
|
||||
Vector3 rightHandLebarEuler = otherCarParts.rightHandLebar.transform.localEulerAngles;
|
||||
Vector3 lefttHandLebarEuler = otherCarParts.leftHandLebar.transform.localEulerAngles;
|
||||
|
||||
otherCarParts.rightHandLebar.transform.localRotation = Quaternion.Euler (settings.steerAngleLimit * rightInput * 2, rightHandLebarEuler.y, rightHandLebarEuler.z);
|
||||
otherCarParts.leftHandLebar.transform.localRotation = Quaternion.Euler (settings.steerAngleLimit * leftInput * 2, lefttHandLebarEuler.y, lefttHandLebarEuler.z);
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
if (currentSpeed < 5) {
|
||||
//check the current rotation of the vehicle with respect to the normal of the gravity normal component, which always point the up direction
|
||||
float angle = Vector3.Angle (currentNormal, transform.up);
|
||||
|
||||
if (angle > 60 && !rotating) {
|
||||
|
||||
resetTimer += Time.deltaTime;
|
||||
|
||||
if (resetTimer > timeToFlip) {
|
||||
resetTimer = 0;
|
||||
StartCoroutine (rotateVehicle ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (!usingGravityControl && isTurnedOn) {
|
||||
if (usingHoverBoardWaypoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
surfaceDetected = false;
|
||||
|
||||
if (increaseHeightIfSurfaceBelowFound) {
|
||||
|
||||
if (Physics.Raycast (surfaceBelowRaycastPosition.position, -transform.up, out hit, raycastDistanceToCheckSurfaceBelow, settings.layer)) {
|
||||
if (hit.distance < minDistanceToIncreaseHeight) {
|
||||
increasingHeightFromSurfaceDetected = true;
|
||||
|
||||
inputIncreaseHeightState (true);
|
||||
|
||||
} else {
|
||||
if (increasingHeightFromSurfaceDetected) {
|
||||
inputIncreaseHeightState (false);
|
||||
|
||||
increasingHeightFromSurfaceDetected = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (increasingHeightFromSurfaceDetected) {
|
||||
inputIncreaseHeightState (false);
|
||||
|
||||
increasingHeightFromSurfaceDetected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Physics.Raycast (groundRaycastPosition.position, -transform.up, out hit, groundRaycastDistance, settings.layer)) {
|
||||
|
||||
currentHitDistance = hit.distance;
|
||||
|
||||
surfaceDetected = true;
|
||||
}
|
||||
|
||||
if (surfaceDetected) {
|
||||
float proportionalHeight = (groundRaycastDistance - currentHitDistance) / groundRaycastDistance;
|
||||
|
||||
appliedHoverForce = (proportionalHeight * hoverForce) * vehicleCameraTransform.up +
|
||||
((Mathf.Cos (Time.time * extraHoverSpeed)) / 2) * transform.up;
|
||||
|
||||
mainVehicleGravityControl.setGravityForcePausedState (false);
|
||||
|
||||
groundFound = true;
|
||||
} else {
|
||||
|
||||
if (isTurnedOn) {
|
||||
mainVehicleGravityControl.setGravityForcePausedState (true);
|
||||
} else {
|
||||
mainVehicleGravityControl.setGravityForcePausedState (false);
|
||||
}
|
||||
|
||||
groundFound = false;
|
||||
}
|
||||
|
||||
if (!groundFound) {
|
||||
if (!moving) {
|
||||
appliedHoverForce = ((Mathf.Cos (Time.time * extraHoverSpeed)) / 2) * hoverFoeceOnAir * transform.up;
|
||||
} else {
|
||||
appliedHoverForce = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (groundFound && heightInput < 0) {
|
||||
heightInput = 0;
|
||||
}
|
||||
|
||||
newVelocity = (motorInput * forwardSpeed) * transform.forward +
|
||||
(horizontalAxis * rightSpeed) * transform.right +
|
||||
(heightInput * upSpeed) * transform.up;
|
||||
|
||||
newVelocity += appliedHoverForce;
|
||||
|
||||
newVelocity *= boostInput;
|
||||
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, newVelocity, Time.deltaTime * velocityChangeSpeed);
|
||||
|
||||
if (rollDirection != 0) {
|
||||
transform.Rotate (0, -rollDirection * rollRotationSpeed, 0);
|
||||
}
|
||||
|
||||
Vector3 predictedUp = Quaternion.AngleAxis (mainRigidbody.angularVelocity.magnitude * Mathf.Rad2Deg * stabilityForce / stabilitySpeed, mainRigidbody.angularVelocity) * transform.up;
|
||||
|
||||
Vector3 torqueVector = Vector3.Cross (predictedUp, vehicleCameraTransform.up);
|
||||
|
||||
mainRigidbody.AddTorque ((stabilitySpeed * stabilitySpeed) * torqueVector);
|
||||
|
||||
currentSpeed = mainRigidbody.linearVelocity.magnitude;
|
||||
|
||||
currenLeftEngineArmRotation = (heightInput * engineArmRotationAmountForward) * Vector3.forward +
|
||||
(motorInput * engineArmRotationAmountRight) * Vector3.right -
|
||||
(horizontalAxis * engineArmRotationAmountForward) * Vector3.forward -
|
||||
(rollDirection * engineArmRotationAmountRight) * Vector3.right;
|
||||
|
||||
currenLeftEngineArmRotation.x =
|
||||
Mathf.Clamp (currenLeftEngineArmRotation.x, -engineArmRotationAmountRight - engineArmExtraRotationAmount, engineArmRotationAmountRight + engineArmExtraRotationAmount);
|
||||
currenLeftEngineArmRotation.z =
|
||||
Mathf.Clamp (currenLeftEngineArmRotation.z, -engineArmRotationAmountForward - engineArmExtraRotationAmount, engineArmRotationAmountForward + engineArmExtraRotationAmount);
|
||||
|
||||
leftEngineArmTransform.localRotation =
|
||||
Quaternion.Lerp (leftEngineArmTransform.localRotation, Quaternion.Euler (currenLeftEngineArmRotation), Time.deltaTime * engineArmRotationSpeed);
|
||||
|
||||
|
||||
currenRightEngineRotation = (-heightInput * engineArmRotationAmountForward) * Vector3.forward +
|
||||
(motorInput * engineArmRotationAmountRight) * Vector3.right -
|
||||
(horizontalAxis * engineArmRotationAmountForward) * Vector3.forward +
|
||||
(rollDirection * engineArmRotationAmountRight) * Vector3.right;
|
||||
|
||||
currenRightEngineRotation.x =
|
||||
Mathf.Clamp (currenRightEngineRotation.x, -engineArmRotationAmountRight - engineArmExtraRotationAmount, engineArmRotationAmountRight + engineArmExtraRotationAmount);
|
||||
currenRightEngineRotation.z =
|
||||
Mathf.Clamp (currenRightEngineRotation.z, -engineArmRotationAmountForward - engineArmExtraRotationAmount, engineArmRotationAmountForward + engineArmExtraRotationAmount);
|
||||
|
||||
rightEngineArmTransform.localRotation = Quaternion.Lerp (rightEngineArmTransform.localRotation, Quaternion.Euler (currenRightEngineRotation), Time.deltaTime * engineArmRotationSpeed);
|
||||
|
||||
rightEngineTransform.Rotate (0, engineRotationSpeed * Time.deltaTime, 0);
|
||||
|
||||
leftEngineTransform.Rotate (0, engineRotationSpeed * Time.deltaTime, 0);
|
||||
}
|
||||
|
||||
if (isTurnedOn) {
|
||||
checkVehicleTurnedOn = true;
|
||||
|
||||
//set the exhaust particles state
|
||||
for (i = 0; i < otherCarParts.normalExhaust.Count; i++) {
|
||||
if (isTurnedOn && currentSpeed < 20) {
|
||||
if (!otherCarParts.normalExhaust [i].isPlaying) {
|
||||
otherCarParts.normalExhaust [i].Play ();
|
||||
}
|
||||
} else {
|
||||
if (otherCarParts.normalExhaust [i].isPlaying) {
|
||||
otherCarParts.normalExhaust [i].Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < otherCarParts.heavyExhaust.Count; i++) {
|
||||
if (isTurnedOn && currentSpeed > 10 && motorInput > 0.1f) {
|
||||
if (!otherCarParts.heavyExhaust [i].isPlaying) {
|
||||
otherCarParts.heavyExhaust [i].Play ();
|
||||
}
|
||||
} else {
|
||||
if (otherCarParts.heavyExhaust [i].isPlaying) {
|
||||
otherCarParts.heavyExhaust [i].Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkVehicleTurnedOn) {
|
||||
stopVehicleParticles ();
|
||||
checkVehicleTurnedOn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the vehicle is using the gravity control, set the state in this component
|
||||
public override void changeGravityControlUse (bool state)
|
||||
{
|
||||
base.changeGravityControlUse (state);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
base.changeVehicleState ();
|
||||
|
||||
mainVehicleGravityControl.setGravityForcePausedState (false);
|
||||
}
|
||||
|
||||
public override void setTurnOnState ()
|
||||
{
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, true, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, true, false);
|
||||
}
|
||||
|
||||
public override void setTurnOffState (bool previouslyTurnedOn)
|
||||
{
|
||||
base.setTurnOffState (previouslyTurnedOn);
|
||||
|
||||
if (previouslyTurnedOn) {
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, true);
|
||||
setAudioState (otherCarParts.engineEndAudioElement, 5, 1, false, true, false);
|
||||
}
|
||||
|
||||
steerInput = 0;
|
||||
|
||||
mainVehicleGravityControl.setGravityForcePausedState (false);
|
||||
}
|
||||
|
||||
public override bool isDrivingActive ()
|
||||
{
|
||||
return driving;
|
||||
}
|
||||
|
||||
public override void setEngineOnOrOffState ()
|
||||
{
|
||||
base.setEngineOnOrOffState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
{
|
||||
base.turnOnOrOff (state, previouslyTurnedOn);
|
||||
|
||||
mainVehicleGravityControl.setCheckDownSpeedActiveState (!isTurnedOn);
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
//stop the audio sources
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, false, false);
|
||||
|
||||
setTurnOffState (false);
|
||||
|
||||
//disable the exhausts particles
|
||||
stopVehicleParticles ();
|
||||
|
||||
//disable the controller
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
public void stopVehicleParticles ()
|
||||
{
|
||||
for (i = 0; i < otherCarParts.normalExhaust.Count; i++) {
|
||||
otherCarParts.normalExhaust [i].Stop ();
|
||||
}
|
||||
|
||||
for (i = 0; i < otherCarParts.heavyExhaust.Count; i++) {
|
||||
otherCarParts.heavyExhaust [i].Stop ();
|
||||
}
|
||||
|
||||
for (int i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
var boostingParticlesMain = otherCarParts.boostingParticles [i].main;
|
||||
boostingParticlesMain.loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
IEnumerator rotateVehicle ()
|
||||
{
|
||||
rotating = true;
|
||||
|
||||
Quaternion currentRotation = transform.rotation;
|
||||
|
||||
//rotate in the forward direction of the vehicle
|
||||
Quaternion dstRotPlayer = Quaternion.LookRotation (transform.forward, currentNormal);
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
transform.rotation = Quaternion.Slerp (currentRotation, dstRotPlayer, t);
|
||||
mainRigidbody.linearVelocity = Vector3.zero;
|
||||
yield return null;
|
||||
|
||||
}
|
||||
rotating = false;
|
||||
}
|
||||
|
||||
//if the vehicle is using the boost, set the boost particles
|
||||
public override void usingBoosting ()
|
||||
{
|
||||
base.usingBoosting ();
|
||||
|
||||
for (int i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
if (usingBoost) {
|
||||
if (!otherCarParts.boostingParticles [i].isPlaying) {
|
||||
otherCarParts.boostingParticles [i].gameObject.SetActive (true);
|
||||
otherCarParts.boostingParticles [i].Play ();
|
||||
|
||||
var boostingParticlesMain = otherCarParts.boostingParticles [i].main;
|
||||
boostingParticlesMain.loop = true;
|
||||
}
|
||||
} else {
|
||||
if (otherCarParts.boostingParticles [i].isPlaying) {
|
||||
var boostingParticlesMain = otherCarParts.boostingParticles [i].main;
|
||||
boostingParticlesMain.loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//OVERRIDE FUNCTIONS FOR VEHICLE CONTROLLER
|
||||
|
||||
//if any collider in the vehicle collides, then
|
||||
public override void setCollisionDetected (Collision currentCollision)
|
||||
{
|
||||
//check that the collision is not with the player
|
||||
if (!currentCollision.gameObject.CompareTag ("Player")) {
|
||||
//if the velocity of the collision is higher that the limit
|
||||
if (currentCollision.relativeVelocity.magnitude > collisionForceLimit) {
|
||||
//set the collision audio with a random collision clip
|
||||
if (otherCarParts.crashAudioElements.Length > 0) {
|
||||
setAudioState (otherCarParts.crashAudioElements [UnityEngine.Random.Range (0, otherCarParts.crashAudioElements.Length)], 5, 1, false, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void startBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void endBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override float getCurrentSpeed ()
|
||||
{
|
||||
return currentSpeed;
|
||||
}
|
||||
|
||||
public override void updateMovingState ()
|
||||
{
|
||||
moving = verticalAxis != 0 || horizontalAxis != 0 || heightInput != 0 || rollDirection != 0;
|
||||
}
|
||||
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public override void inputHoldOrReleaseTurbo (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && !usingHoverBoardWaypoint) {
|
||||
//boost input
|
||||
if (holdingButton) {
|
||||
usingBoost = true;
|
||||
|
||||
//set the camera move away action
|
||||
mainVehicleCameraController.usingBoost (true, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
} else {
|
||||
//stop boost
|
||||
usingBoost = false;
|
||||
|
||||
//disable the camera move away action
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
|
||||
//disable the boost particles
|
||||
usingBoosting ();
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputSetTurnOnState ()
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
if (mainVehicleHUDManager.canSetTurnOnState) {
|
||||
setEngineOnOrOffState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHorn ()
|
||||
{
|
||||
if (driving) {
|
||||
setAudioState (otherCarParts.hornAudioElement, 5, 1, false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputIncreaseHeightState (bool state)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn) {
|
||||
if (state) {
|
||||
if (usingHoverBoardWaypoint) {
|
||||
pickOrReleaseHoverboardVehicle (false, false);
|
||||
|
||||
Vector3 totalJumpForce = mainRigidbody.mass * hoverboardJumpForce * (currentNormal + transform.forward);
|
||||
|
||||
if (useHoverboardJumpClamp) {
|
||||
totalJumpForce = Vector3.ClampMagnitude (totalJumpForce, hoverboardJumpClamp);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalJumpForce, ForceMode.Impulse);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
heightInput = 1;
|
||||
} else {
|
||||
heightInput = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputDecreaseHeightState (bool state)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn) {
|
||||
if (state) {
|
||||
heightInput = -1;
|
||||
} else {
|
||||
heightInput = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetRotateToLeftState (bool state)
|
||||
{
|
||||
if (driving && isTurnedOn) {
|
||||
if (!playerMovingOn3dWorld) {
|
||||
rollDirection = 0;
|
||||
|
||||
usingRollInput = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
rollDirection = 1;
|
||||
} else {
|
||||
rollDirection = 0;
|
||||
}
|
||||
|
||||
usingRollInput = state;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetRotateToRightState (bool state)
|
||||
{
|
||||
if (driving && isTurnedOn) {
|
||||
if (!playerMovingOn3dWorld) {
|
||||
rollDirection = 0;
|
||||
|
||||
usingRollInput = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
rollDirection = -1;
|
||||
} else {
|
||||
rollDirection = 0;
|
||||
}
|
||||
|
||||
usingRollInput = state;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class otherVehicleParts
|
||||
{
|
||||
public Transform rightHandLebar;
|
||||
public Transform leftHandLebar;
|
||||
public Transform COM;
|
||||
public GameObject chassis;
|
||||
public AudioClip engineStartClip;
|
||||
public AudioElement engineStartAudioElement;
|
||||
public AudioClip engineClip;
|
||||
public AudioElement engineAudioElement;
|
||||
public AudioClip engineEndClip;
|
||||
public AudioElement engineEndAudioElement;
|
||||
public AudioClip[] crashClips;
|
||||
public AudioElement[] crashAudioElements;
|
||||
public AudioClip hornClip;
|
||||
public AudioElement hornAudioElement;
|
||||
public List<ParticleSystem> normalExhaust = new List<ParticleSystem> ();
|
||||
public List<ParticleSystem> heavyExhaust = new List<ParticleSystem> ();
|
||||
public AudioSource engineStartAudio;
|
||||
public AudioSource engineAudio;
|
||||
public AudioSource crashAudio;
|
||||
public AudioSource hornAudio;
|
||||
public List<ParticleSystem> boostingParticles = new List<ParticleSystem> ();
|
||||
|
||||
public void InitializeAudioElements ()
|
||||
{
|
||||
if (engineStartClip != null) {
|
||||
engineStartAudioElement.clip = engineStartClip;
|
||||
}
|
||||
|
||||
if (engineClip != null) {
|
||||
engineAudioElement.clip = engineClip;
|
||||
}
|
||||
|
||||
if (engineEndClip != null) {
|
||||
engineEndAudioElement.clip = engineEndClip;
|
||||
}
|
||||
|
||||
if (crashClips != null && crashClips.Length > 0) {
|
||||
crashAudioElements = new AudioElement[crashClips.Length];
|
||||
|
||||
for (var i = 0; i < crashClips.Length; i++) {
|
||||
crashAudioElements [i] = new AudioElement { clip = crashClips [i] };
|
||||
}
|
||||
}
|
||||
|
||||
if (hornClip != null) {
|
||||
hornAudioElement.clip = hornClip;
|
||||
}
|
||||
|
||||
if (engineStartAudio != null) {
|
||||
engineStartAudioElement.audioSource = engineStartAudio;
|
||||
}
|
||||
|
||||
if (engineAudio != null) {
|
||||
engineAudioElement.audioSource = engineAudio;
|
||||
engineEndAudioElement.audioSource = engineAudio;
|
||||
}
|
||||
|
||||
if (crashAudio != null) {
|
||||
foreach (var audioElement in crashAudioElements) {
|
||||
audioElement.audioSource = crashAudio;
|
||||
}
|
||||
}
|
||||
|
||||
if (hornAudio != null) {
|
||||
hornAudioElement.audioSource = hornAudio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehicletSettings
|
||||
{
|
||||
public LayerMask layer;
|
||||
public float steerAngleLimit;
|
||||
public float increaseHeightSpeed = 2;
|
||||
public float decreaseHeightSpeed = 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78778710b85e18a4691e7fe44ef4983a
|
||||
timeCreated: 1551571300
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/flyingController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,210 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class hoverBoardAnimationSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float extraBodyRotation = -20;
|
||||
public float extraSpineRotation = 30;
|
||||
public float limitBodyRotationX = 30;
|
||||
public float limitBodyRotationZ = 30;
|
||||
public float minSpineRotationX = 20;
|
||||
public float maxSpineRotationX = 330;
|
||||
public float maxArmsRotation = 25;
|
||||
|
||||
public bool addMovementToBody;
|
||||
public bool addExtraMovementToBody;
|
||||
public bool addMovementToArms;
|
||||
public bool addMovementToHead;
|
||||
|
||||
public float maxHeadRotationBackward;
|
||||
public float headRotationSpeed;
|
||||
public float minBackwardVelocityToHeadRotation;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform headLookCenter;
|
||||
|
||||
public Transform bodyLookCenter;
|
||||
public Transform bodyLookPivot;
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
public hoverBoardController mainHoverBoardController;
|
||||
public Transform hoverBoardTransform;
|
||||
|
||||
public Transform playerGravityCenter;
|
||||
|
||||
upperBodyRotationSystem mainUpperBodyRotationSystem;
|
||||
|
||||
Vector3 currentNormal;
|
||||
|
||||
float gravityCenterAngleX;
|
||||
float gravityCenterAngleZ;
|
||||
float angleZ;
|
||||
float currentExtraBodyRotation;
|
||||
float currentExtraSpineRotation;
|
||||
float headLookCenterCurrentRotation;
|
||||
|
||||
bool driving;
|
||||
|
||||
Animator animator;
|
||||
Transform rightArm;
|
||||
Transform leftArm;
|
||||
|
||||
bool firstPersonActive;
|
||||
|
||||
bool animationActive;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
currentExtraBodyRotation = extraBodyRotation;
|
||||
currentExtraSpineRotation = extraSpineRotation;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (driving) {
|
||||
firstPersonActive = mainHoverBoardController.firstPersonActive;
|
||||
|
||||
if (!firstPersonActive && animationActive) {
|
||||
currentNormal = mainHoverBoardController.getNormal ();
|
||||
|
||||
currentNormal = currentNormal.normalized;
|
||||
|
||||
angleZ = Mathf.Asin (hoverBoardTransform.InverseTransformDirection (Vector3.Cross (currentNormal, hoverBoardTransform.up)).z) * Mathf.Rad2Deg;
|
||||
|
||||
float angleX = Mathf.Asin (hoverBoardTransform.InverseTransformDirection (Vector3.Cross (currentNormal, hoverBoardTransform.up)).x) * Mathf.Rad2Deg;
|
||||
|
||||
float gravityAngleZ = 0;
|
||||
|
||||
if (Mathf.Abs (angleZ) > 1) {
|
||||
gravityAngleZ = -angleZ;
|
||||
} else {
|
||||
gravityAngleZ = 0;
|
||||
}
|
||||
|
||||
float gravityAngleX = 0;
|
||||
|
||||
if (Mathf.Abs (angleX) > 1) {
|
||||
gravityAngleX = -angleX;
|
||||
} else {
|
||||
gravityAngleX = 0;
|
||||
}
|
||||
|
||||
gravityCenterAngleX = Mathf.Lerp (gravityCenterAngleX, gravityAngleX, Time.deltaTime * 5);
|
||||
gravityCenterAngleZ = Mathf.Lerp (gravityCenterAngleZ, gravityAngleZ, Time.deltaTime * 5);
|
||||
gravityCenterAngleX = Mathf.Clamp (gravityCenterAngleX, -limitBodyRotationX, limitBodyRotationX);
|
||||
gravityCenterAngleZ = Mathf.Clamp (gravityCenterAngleZ, -limitBodyRotationZ, limitBodyRotationZ);
|
||||
|
||||
playerGravityCenter.localEulerAngles = new Vector3 (gravityCenterAngleX, currentExtraBodyRotation, gravityCenterAngleZ);
|
||||
|
||||
float forwardSpeed = (mainRigidbody.transform.InverseTransformDirection (mainRigidbody.linearVelocity).z) * 3f;
|
||||
float bodyRotation = extraBodyRotation;
|
||||
float spineRotation = extraSpineRotation;
|
||||
|
||||
if (forwardSpeed < -2) {
|
||||
bodyRotation = -extraBodyRotation;
|
||||
spineRotation = -extraSpineRotation;
|
||||
}
|
||||
|
||||
currentExtraBodyRotation = Mathf.Lerp (currentExtraBodyRotation, bodyRotation, Time.deltaTime * 5);
|
||||
currentExtraSpineRotation = Mathf.Lerp (currentExtraSpineRotation, spineRotation, Time.deltaTime * 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate ()
|
||||
{
|
||||
if (driving && !firstPersonActive && animationActive) {
|
||||
if (addExtraMovementToBody) {
|
||||
Quaternion rotationX = Quaternion.FromToRotation (bodyLookPivot.InverseTransformDirection (hoverBoardTransform.right),
|
||||
bodyLookPivot.InverseTransformDirection (hoverBoardTransform.forward));
|
||||
|
||||
Vector3 directionX = rotationX.eulerAngles;
|
||||
|
||||
Quaternion rotationZ = Quaternion.FromToRotation (bodyLookPivot.InverseTransformDirection (hoverBoardTransform.forward),
|
||||
bodyLookPivot.InverseTransformDirection (hoverBoardTransform.forward));
|
||||
|
||||
Vector3 directionZ = rotationZ.eulerAngles;
|
||||
|
||||
float angleX = directionX.x;
|
||||
|
||||
if (angleX > 180) {
|
||||
angleX = Mathf.Clamp (angleX, maxSpineRotationX, 360);
|
||||
} else {
|
||||
angleX = Mathf.Clamp (angleX, 0, minSpineRotationX);
|
||||
}
|
||||
|
||||
bodyLookPivot.localEulerAngles = new Vector3 (angleX - angleZ, bodyLookPivot.localEulerAngles.y, directionZ.z - currentExtraSpineRotation);
|
||||
}
|
||||
|
||||
if (addMovementToArms) {
|
||||
float armRotation = angleZ;
|
||||
armRotation = Mathf.Clamp (armRotation, -maxArmsRotation, maxArmsRotation);
|
||||
|
||||
float rightArmRotationX = rightArm.localEulerAngles.x - armRotation;
|
||||
rightArm.localEulerAngles = new Vector3 (rightArmRotationX, rightArm.localEulerAngles.y, rightArm.localEulerAngles.z);
|
||||
|
||||
float leftArmRotationX = leftArm.localEulerAngles.x + armRotation;
|
||||
leftArm.localEulerAngles = new Vector3 (leftArmRotationX, leftArm.localEulerAngles.y, leftArm.localEulerAngles.z);
|
||||
}
|
||||
|
||||
if (addMovementToHead) {
|
||||
float headAngle = 0;
|
||||
|
||||
if (mainHoverBoardController.motorInput < 0 &&
|
||||
(Mathf.Abs (mainHoverBoardController.currentSpeed) > minBackwardVelocityToHeadRotation || mainHoverBoardController.motorInput < -0.8f)) {
|
||||
headAngle = maxHeadRotationBackward;
|
||||
}
|
||||
|
||||
headLookCenterCurrentRotation = Mathf.Lerp (headLookCenterCurrentRotation, headAngle, Time.deltaTime * headRotationSpeed);
|
||||
|
||||
headLookCenter.localEulerAngles = new Vector3 (0, headLookCenterCurrentRotation, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public void changeVehicleState (bool state)
|
||||
{
|
||||
driving = state;
|
||||
|
||||
animationActive = state;
|
||||
|
||||
//set the audio values if the player is getting on or off from the vehicle
|
||||
if (driving) {
|
||||
//set the same state in the gravity control components
|
||||
animator = hoverBoardTransform.GetComponentInChildren<Animator> ();
|
||||
|
||||
mainUpperBodyRotationSystem = hoverBoardTransform.GetComponentInChildren<upperBodyRotationSystem> ();
|
||||
|
||||
if (addMovementToBody) {
|
||||
if (mainUpperBodyRotationSystem != null) {
|
||||
mainUpperBodyRotationSystem.enableOrDisableIKUpperBody (true);
|
||||
|
||||
mainUpperBodyRotationSystem.setTemporalObjectToFollow (bodyLookCenter);
|
||||
}
|
||||
}
|
||||
|
||||
bodyLookPivot.localEulerAngles = Vector3.zero;
|
||||
|
||||
if (animator != null) {
|
||||
rightArm = animator.GetBoneTransform (HumanBodyBones.RightUpperArm);
|
||||
leftArm = animator.GetBoneTransform (HumanBodyBones.LeftUpperArm);
|
||||
}
|
||||
} else {
|
||||
if (addMovementToBody) {
|
||||
if (mainUpperBodyRotationSystem != null) {
|
||||
mainUpperBodyRotationSystem.enableOrDisableIKUpperBody (false);
|
||||
|
||||
mainUpperBodyRotationSystem.setTemporalObjectToFollow (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65ed2615d0f1672408d178125cda0868
|
||||
timeCreated: 1613579173
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/hoverBoardAnimationSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,715 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class hoverBoardController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public List<hoverEngineSettings> hoverEngineList = new List<hoverEngineSettings> ();
|
||||
public OtherCarParts otherCarParts;
|
||||
public hoverCraftSettings settings;
|
||||
|
||||
public float stabilityForce = 1;
|
||||
public float stabilitySpeed = 2;
|
||||
|
||||
public float minSteerInputIdle = 0.4f;
|
||||
public float minSteerInputMoving = 0.4f;
|
||||
|
||||
float currentMinSteerInput;
|
||||
|
||||
public hoverBoardAnimationSystem mainHoverBoardAnimationSystem;
|
||||
|
||||
[HideInInspector] public bool firstPersonActive;
|
||||
|
||||
float audioPower = 0;
|
||||
float maxEnginePower;
|
||||
|
||||
float resetTimer;
|
||||
|
||||
float originalJumpPower;
|
||||
|
||||
int i;
|
||||
|
||||
int collisionForceLimit = 5;
|
||||
|
||||
|
||||
bool anyOnGround;
|
||||
bool rotating;
|
||||
|
||||
Vector3 gravityForce;
|
||||
|
||||
hoverEngineSettings currentEngine;
|
||||
|
||||
int hoverEngineListCount;
|
||||
|
||||
ParticleSystem currentParticleSystem;
|
||||
|
||||
Vector3 transformForward;
|
||||
Vector3 transformUp;
|
||||
|
||||
|
||||
protected override void InitializeAudioElements ()
|
||||
{
|
||||
otherCarParts.InitializeAudioElements ();
|
||||
}
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
|
||||
}
|
||||
|
||||
public override void Start ()
|
||||
{
|
||||
base.Start ();
|
||||
|
||||
//get the boost particles inside the vehicle
|
||||
hoverEngineListCount = hoverEngineList.Count;
|
||||
|
||||
for (i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
if (otherCarParts.boostingParticles [i].gameObject.activeSelf) {
|
||||
otherCarParts.boostingParticles [i].gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < hoverEngineList.Count; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
currentEngine.hasTurbine = currentEngine.turbine != null;
|
||||
|
||||
currentEngine.hasParticles = currentEngine.ParticleSystem != null;
|
||||
}
|
||||
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, false, false);
|
||||
|
||||
otherCarParts.gravityCenterCollider.enabled = false;
|
||||
originalJumpPower = vehicleControllerSettings.jumpPower;
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
base.vehicleUpdate ();
|
||||
|
||||
|
||||
mainRigidbody.centerOfMass = settings.centerOfMassOffset;
|
||||
|
||||
maxEnginePower = 0;
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.maxEnginePower > maxEnginePower) {
|
||||
maxEnginePower = currentEngine.maxEnginePower;
|
||||
}
|
||||
|
||||
//configure every particle system according to the engine state
|
||||
float rpm = Mathf.Lerp (currentEngine.minRPM, currentEngine.maxRPM, currentEngine.maxEnginePower);
|
||||
|
||||
if (currentEngine.hasTurbine) {
|
||||
currentEngine.turbine.Rotate (0, rpm * Time.deltaTime * 6, 0);
|
||||
}
|
||||
|
||||
if (currentEngine.hasParticles) {
|
||||
var hoverEngineParticleEmission = currentEngine.ParticleSystem.emission;
|
||||
hoverEngineParticleEmission.rateOverTime = currentEngine.maxEmission * currentEngine.maxEnginePower;
|
||||
|
||||
currentEngine.ParticleSystem.transform.position = currentEngine.hit.point + currentEngine.dustHeight * currentEngine.hit.normal;
|
||||
|
||||
currentEngine.ParticleSystem.transform.LookAt (currentEngine.hit.point + 10 * currentEngine.hit.normal);
|
||||
}
|
||||
}
|
||||
|
||||
audioPower = Mathf.Lerp (maxEnginePower, motorInput, settings.audioEngineSpeed);
|
||||
|
||||
otherCarParts.engineAudio.volume = Mathf.Lerp (settings.engineMinVolume, settings.engineMaxVolume, audioPower);
|
||||
otherCarParts.engineAudio.pitch = Mathf.Lerp (settings.minAudioPitch, settings.maxAudioPitch, audioPower);
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
if (currentSpeed < 5) {
|
||||
//check the current rotation of the vehicle with respect to the normal of the gravity normal component, which always point the up direction
|
||||
float angle = Vector3.Angle (currentNormal, transform.up);
|
||||
|
||||
if (angle > 60 && !rotating) {
|
||||
resetTimer += Time.deltaTime;
|
||||
|
||||
if (resetTimer > settings.timeToFlip) {
|
||||
resetTimer = 0;
|
||||
|
||||
StartCoroutine (rotateVehicle ());
|
||||
}
|
||||
} else {
|
||||
resetTimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
currentSpeed = mainRigidbody.linearVelocity.magnitude;
|
||||
|
||||
//apply turn
|
||||
if (usingHoverBoardWaypoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mathf.Approximately (horizontalAxis, 0)) {
|
||||
float localR = Vector3.Dot (mainRigidbody.angularVelocity, transform.up);
|
||||
|
||||
mainRigidbody.AddRelativeTorque (0, -localR * settings.brakingTorque, 0);
|
||||
} else {
|
||||
float targetRoll = -settings.rollOnTurns * horizontalAxis;
|
||||
float roll = Mathf.Asin (transform.right.y) * Mathf.Rad2Deg;
|
||||
|
||||
// only apply additional roll if we're not "overrolled"
|
||||
if (Mathf.Abs (roll) > Mathf.Abs (targetRoll)) {
|
||||
roll = 0;
|
||||
} else {
|
||||
roll = Mathf.DeltaAngle (roll, targetRoll);
|
||||
}
|
||||
|
||||
mainRigidbody.AddRelativeTorque (0, horizontalAxis * settings.steeringTorque, roll * settings.rollOnTurnsTorque);
|
||||
}
|
||||
|
||||
if (!usingGravityControl && !jumpInputPressed) {
|
||||
Vector3 localVelocity = transform.InverseTransformDirection (mainRigidbody.linearVelocity);
|
||||
Vector3 extraForce = Vector3.Scale (settings.extraRigidbodyForce, localVelocity);
|
||||
|
||||
mainRigidbody.AddRelativeForce (mainRigidbody.mass * (-extraForce));
|
||||
|
||||
//use every engine to keep the vehicle in the air
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (!currentEngine.mainEngine) {
|
||||
//find force direction by rotating local up vector towards world up
|
||||
Vector3 engineUp = currentEngine.engineTransform.up;
|
||||
|
||||
Vector3 enginePosition = currentEngine.engineTransform.position;
|
||||
|
||||
gravityForce = (9.8f * currentNormal).normalized;
|
||||
|
||||
engineUp = Vector3.RotateTowards (engineUp, gravityForce, currentEngine.maxEngineAngle * Mathf.Deg2Rad, 1);
|
||||
|
||||
//check if the vehicle is on ground
|
||||
currentEngine.maxEnginePower = 0;
|
||||
|
||||
if (Physics.Raycast (enginePosition, -engineUp, out currentEngine.hit, currentEngine.maxHeight, settings.layer)) {
|
||||
//calculate down force
|
||||
currentEngine.maxEnginePower = Mathf.Pow ((currentEngine.maxHeight - currentEngine.hit.distance) / currentEngine.maxHeight, currentEngine.Exponent);
|
||||
|
||||
float force = currentEngine.maxEnginePower * currentEngine.engineForce;
|
||||
|
||||
float velocityUp = Vector3.Dot (mainRigidbody.GetPointVelocity (enginePosition), engineUp);
|
||||
|
||||
float drag = -velocityUp * Mathf.Abs (velocityUp) * currentEngine.damping;
|
||||
|
||||
mainRigidbody.AddForceAtPosition ((force + drag) * engineUp, enginePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 torqueVector = Vector3.Cross (transform.up, mainVehicleCameraController.transform.up);
|
||||
|
||||
mainRigidbody.AddTorque ((stabilityForce * stabilitySpeed) * torqueVector);
|
||||
|
||||
//if the handbrake is pressed, set the brake torque value in every wheel
|
||||
bool brakeActive = (braking || isBrakeActive ());
|
||||
|
||||
if (brakeActive) {
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.mainEngine) {
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, Vector3.zero, Time.deltaTime);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
transformForward = transform.forward;
|
||||
transformUp = transform.up;
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.mainEngine) {
|
||||
float movementMultiplier = settings.inAirMovementMultiplier;
|
||||
|
||||
if (Physics.Raycast (currentEngine.engineTransform.position, -transformUp, out currentEngine.hit, currentEngine.maxHeight, settings.layer)) {
|
||||
movementMultiplier = 1;
|
||||
}
|
||||
|
||||
gravityForce = (9.8f * currentNormal).normalized;
|
||||
|
||||
//current speed along forward axis
|
||||
float speed = Vector3.Dot (mainRigidbody.linearVelocity, transformForward);
|
||||
|
||||
//if the vehicle doesn't move by input, apply automatic brake
|
||||
bool isAutoBraking = Mathf.Approximately (motorInput, 0) && settings.autoBrakingDeceleration > 0;
|
||||
|
||||
float thrust = motorInput;
|
||||
|
||||
if (isAutoBraking) {
|
||||
thrust = -Mathf.Sign (speed) * settings.autoBrakingDeceleration / settings.maxBrakingDeceleration;
|
||||
}
|
||||
|
||||
//check if it is braking, for example speed and thrust have opposing signs
|
||||
bool isBraking = speed * motorInput < 0;
|
||||
|
||||
//don't apply force if speed is max already
|
||||
if (Mathf.Abs (speed) < settings.maxSpeed || isBraking) {
|
||||
//position on speed curve
|
||||
float normSpeed = Mathf.Sign (motorInput) * speed / settings.maxSpeed;
|
||||
|
||||
//apply acceleration curve and select proper maximum value
|
||||
float acc = settings.accelerationCurve.Evaluate (normSpeed) * (isBraking ? settings.maxBrakingDeceleration : thrust > 0 ? settings.maxForwardAcceleration : settings.maxReverseAcceleration);
|
||||
|
||||
//drag should be added to the acceleration
|
||||
float sdd = speed * settings.extraRigidbodyForce.z;
|
||||
float dragForce = sdd + mainRigidbody.linearDamping * speed;
|
||||
float force = acc * thrust + dragForce;
|
||||
|
||||
//reduce acceleration if the vehicle is close to vertical orientation and is trrying to go higher
|
||||
float y = Vector3.Dot (transformForward, gravityForce);
|
||||
|
||||
if (settings.maxSurfaceAngle < 90 && y * thrust > 0) {
|
||||
if (!isAutoBraking) {
|
||||
float pitch2 = Mathf.Asin (Mathf.Abs (y)) * Mathf.Rad2Deg;
|
||||
|
||||
if (pitch2 > settings.maxSurfaceAngle) {
|
||||
float forceDecrease = (pitch2 - settings.maxSurfaceAngle) / (90 - settings.maxSurfaceAngle) * settings.maxSurfaceVerticalReduction;
|
||||
|
||||
force /= 1 + forceDecrease;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce ((force * boostInput * movementMultiplier) * transformForward, ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
anyOnGround = true;
|
||||
|
||||
int totalWheelsOnAir = 0;
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (!Physics.Raycast (currentEngine.engineTransform.position, -currentEngine.engineTransform.up, out currentEngine.hit, currentEngine.maxHeight, settings.layer)) {
|
||||
totalWheelsOnAir++;
|
||||
}
|
||||
}
|
||||
|
||||
//if the total amount of wheels in the air is equal to the number of wheel sin the vehicle, anyOnGround is false
|
||||
if (totalWheelsOnAir == hoverEngineListCount && anyOnGround) {
|
||||
anyOnGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator jumpCoroutine ()
|
||||
{
|
||||
jumpInputPressed = true;
|
||||
|
||||
yield return new WaitForSeconds (0.5f);
|
||||
|
||||
jumpInputPressed = false;
|
||||
}
|
||||
|
||||
public override void enterOrExitFromWayPoint (bool state)
|
||||
{
|
||||
usingHoverBoardWaypoint = state;
|
||||
|
||||
mainVehicleGravityControl.enabled = !state;
|
||||
|
||||
mainRigidbody.isKinematic = state;
|
||||
|
||||
if (usingHoverBoardWaypoint) {
|
||||
lastTimeReleasedFromWaypoint = 0;
|
||||
} else {
|
||||
lastTimeReleasedFromWaypoint = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
public override float getLastTimeReleasedFromWaypoint ()
|
||||
{
|
||||
return lastTimeReleasedFromWaypoint;
|
||||
}
|
||||
|
||||
public override bool isUsingHoverBoardWaypoint ()
|
||||
{
|
||||
return usingHoverBoardWaypoint;
|
||||
}
|
||||
|
||||
public override void receiveWayPoints (hoverBoardWayPoints wayPoints)
|
||||
{
|
||||
wayPointsManager = wayPoints;
|
||||
}
|
||||
|
||||
public override void updateCameraSteerState ()
|
||||
{
|
||||
if (localLook.z < 0f) {
|
||||
localLook.x = Mathf.Sign (localLook.x);
|
||||
}
|
||||
|
||||
steering = localLook.x;
|
||||
|
||||
steering = Mathf.Clamp (steering, -1f, 1f);
|
||||
|
||||
if (axisValues.y != 0) {
|
||||
currentMinSteerInput = minSteerInputMoving;
|
||||
} else {
|
||||
currentMinSteerInput = minSteerInputIdle;
|
||||
}
|
||||
|
||||
if (Mathf.Abs (steering) > currentMinSteerInput) {
|
||||
horizontalAxis = steering;
|
||||
} else {
|
||||
horizontalAxis = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//if the vehicle is using the gravity control, set the state in this component
|
||||
public override void changeGravityControlUse (bool state)
|
||||
{
|
||||
base.changeGravityControlUse (state);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
base.changeVehicleState ();
|
||||
|
||||
otherCarParts.gravityCenterCollider.enabled = driving;
|
||||
|
||||
mainHoverBoardAnimationSystem.changeVehicleState (driving);
|
||||
}
|
||||
|
||||
public override void setTurnOnState ()
|
||||
{
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, true, false);
|
||||
}
|
||||
|
||||
public override void setTurnOffState (bool previouslyTurnedOn)
|
||||
{
|
||||
base.setTurnOffState (previouslyTurnedOn);
|
||||
|
||||
if (previouslyTurnedOn) {
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
{
|
||||
base.turnOnOrOff (state, previouslyTurnedOn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override bool isDrivingActive ()
|
||||
{
|
||||
return driving;
|
||||
}
|
||||
|
||||
public override void setEngineOnOrOffState ()
|
||||
{
|
||||
base.setEngineOnOrOffState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
//stop the audio sources
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, false);
|
||||
|
||||
setTurnOffState (false);
|
||||
|
||||
otherCarParts.gravityCenterCollider.enabled = false;
|
||||
|
||||
//disable the controller
|
||||
this.enabled = false;
|
||||
|
||||
mainHoverBoardAnimationSystem.changeVehicleState (false);
|
||||
}
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
IEnumerator rotateVehicle ()
|
||||
{
|
||||
rotating = true;
|
||||
|
||||
Quaternion currentRotation = transform.rotation;
|
||||
//rotate in the forward direction of the vehicle
|
||||
|
||||
Quaternion dstRotPlayer = Quaternion.LookRotation (transform.forward, currentNormal);
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
transform.rotation = Quaternion.Slerp (currentRotation, dstRotPlayer, t);
|
||||
mainRigidbody.linearVelocity = Vector3.zero;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
rotating = false;
|
||||
}
|
||||
|
||||
//if the vehicle is using the boost, set the boost particles
|
||||
public override void usingBoosting ()
|
||||
{
|
||||
base.usingBoosting ();
|
||||
|
||||
for (int i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
currentParticleSystem = otherCarParts.boostingParticles [i];
|
||||
|
||||
if (usingBoost) {
|
||||
if (!currentParticleSystem.isPlaying) {
|
||||
if (!currentParticleSystem.gameObject.activeSelf) {
|
||||
currentParticleSystem.gameObject.SetActive (true);
|
||||
}
|
||||
|
||||
currentParticleSystem.Play ();
|
||||
|
||||
var boostingParticlesMain = currentParticleSystem.main;
|
||||
boostingParticlesMain.loop = true;
|
||||
}
|
||||
} else {
|
||||
if (currentParticleSystem.isPlaying) {
|
||||
var boostingParticlesMain = currentParticleSystem.main;
|
||||
boostingParticlesMain.loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//use a jump platform
|
||||
public void useVehicleJumpPlatform (Vector3 direction)
|
||||
{
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * direction, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public void useJumpPlatformParable (Vector3 direction)
|
||||
{
|
||||
Vector3 jumpForce = direction;
|
||||
|
||||
mainRigidbody.AddForce (jumpForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
public void setNewJumpPower (float newJumpPower)
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = newJumpPower;
|
||||
}
|
||||
|
||||
public void setOriginalJumpPower ()
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = originalJumpPower;
|
||||
}
|
||||
|
||||
public void setCanJumpState (bool state)
|
||||
{
|
||||
vehicleControllerSettings.canJump = state;
|
||||
}
|
||||
|
||||
//OVERRIDE FUNCTIONS FOR VEHICLE CONTROLLER
|
||||
|
||||
//if any collider in the vehicle collides, then
|
||||
public override void setCollisionDetected (Collision currentCollision)
|
||||
{
|
||||
//check that the collision is not with the player
|
||||
if (!currentCollision.gameObject.CompareTag ("Player")) {
|
||||
//if the velocity of the collision is higher that the limit
|
||||
if (currentCollision.relativeVelocity.magnitude > collisionForceLimit) {
|
||||
//set the collision audio with a random collision clip
|
||||
if (otherCarParts.crashAudioElements.Length > 0) {
|
||||
setAudioState (otherCarParts.crashAudioElements [UnityEngine.Random.Range (0, otherCarParts.crashAudioElements.Length)], 5, 1, false, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void startBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
braking = true;
|
||||
}
|
||||
|
||||
public override void endBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
braking = false;
|
||||
}
|
||||
|
||||
public override float getCurrentSpeed ()
|
||||
{
|
||||
return currentSpeed;
|
||||
}
|
||||
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public override void inputJump ()
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && vehicleControllerSettings.canJump) {
|
||||
if (anyOnGround && !jumpInputPressed) {
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * vehicleControllerSettings.jumpPower * currentNormal, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
if (usingHoverBoardWaypoint) {
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
pickOrReleaseHoverboardVehicle (false, false);
|
||||
|
||||
Vector3 totalJumpForce = mainRigidbody.mass * hoverboardJumpForce * (currentNormal + transform.forward);
|
||||
|
||||
if (useHoverboardJumpClamp) {
|
||||
totalJumpForce = Vector3.ClampMagnitude (totalJumpForce, hoverboardJumpClamp);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalJumpForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseTurbo (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && !usingHoverBoardWaypoint) {
|
||||
//boost input
|
||||
if (holdingButton) {
|
||||
if (vehicleControllerSettings.canUseBoost) {
|
||||
usingBoost = true;
|
||||
|
||||
//set the camera move away action
|
||||
mainVehicleCameraController.usingBoost (true, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
}
|
||||
} else {
|
||||
//stop boost
|
||||
usingBoost = false;
|
||||
|
||||
//disable the camera move away action
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
|
||||
//disable the boost particles
|
||||
usingBoosting ();
|
||||
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputSetTurnOnState ()
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
if (mainVehicleHUDManager.canSetTurnOnState) {
|
||||
setEngineOnOrOffState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseBrake (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
braking = holdingButton;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class hoverEngineSettings
|
||||
{
|
||||
public string Name;
|
||||
public Transform engineTransform;
|
||||
public ParticleSystem ParticleSystem;
|
||||
public float maxEmission = 100;
|
||||
public float dustHeight = 0.1f;
|
||||
public float maxHeight = 2;
|
||||
public float engineForce = 300;
|
||||
public float damping = 10;
|
||||
public float Exponent = 2;
|
||||
public float maxEngineAngle = 15;
|
||||
public bool mainEngine;
|
||||
public float minRPM = 100;
|
||||
public float maxRPM = 200;
|
||||
public Transform turbine;
|
||||
[HideInInspector] public RaycastHit hit;
|
||||
[HideInInspector] public float maxEnginePower;
|
||||
|
||||
[HideInInspector] public bool hasTurbine;
|
||||
[HideInInspector] public bool hasParticles;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class OtherCarParts
|
||||
{
|
||||
public Transform COM;
|
||||
public GameObject chassis;
|
||||
public AudioClip engineClip;
|
||||
public AudioElement engineAudioElement;
|
||||
public AudioClip[] crashClips;
|
||||
public AudioElement[] crashAudioElements;
|
||||
public AudioSource engineAudio;
|
||||
public AudioSource crashAudio;
|
||||
public List<ParticleSystem> boostingParticles = new List<ParticleSystem> ();
|
||||
public Collider gravityCenterCollider;
|
||||
|
||||
public void InitializeAudioElements ()
|
||||
{
|
||||
if (engineClip != null) {
|
||||
engineAudioElement.clip = engineClip;
|
||||
}
|
||||
|
||||
if (crashClips != null && crashClips.Length > 0) {
|
||||
crashAudioElements = new AudioElement[crashClips.Length];
|
||||
|
||||
for (var i = 0; i < crashClips.Length; i++) {
|
||||
crashAudioElements [i] = new AudioElement { clip = crashClips [i] };
|
||||
}
|
||||
}
|
||||
|
||||
if (engineAudio != null) {
|
||||
engineAudioElement.audioSource = engineAudio;
|
||||
}
|
||||
|
||||
if (crashAudio != null) {
|
||||
foreach (var audioElement in crashAudioElements) {
|
||||
audioElement.audioSource = crashAudio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class hoverCraftSettings
|
||||
{
|
||||
public LayerMask layer;
|
||||
public float steeringTorque = 120;
|
||||
public float brakingTorque = 200;
|
||||
public float maxSpeed = 30;
|
||||
public float maxForwardAcceleration = 20;
|
||||
public float maxReverseAcceleration = 15;
|
||||
public float maxBrakingDeceleration = 30;
|
||||
public float autoBrakingDeceleration = 20;
|
||||
public float rollOnTurns = 10;
|
||||
public float rollOnTurnsTorque = 10;
|
||||
public float timeToFlip = 2;
|
||||
public float audioEngineSpeed = 0.5f;
|
||||
public float engineMinVolume = 0.5f;
|
||||
public float engineMaxVolume = 1;
|
||||
public float minAudioPitch = 0.4f;
|
||||
public float maxAudioPitch = 1;
|
||||
public AnimationCurve accelerationCurve;
|
||||
public float maxSurfaceVerticalReduction = 10;
|
||||
public float maxSurfaceAngle = 110;
|
||||
public Vector3 extraRigidbodyForce = new Vector3 (2, 0.1f, 0.2f);
|
||||
public Vector3 centerOfMassOffset;
|
||||
[Range (0, 1)] public float inAirMovementMultiplier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3ea73ff3e032e84782cb52826cc8b0c
|
||||
timeCreated: 1468588219
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/hoverBoardController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,830 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class hoverCraftController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public float maxSteeringTorque = 1400;
|
||||
public float rollOnTurns = 10;
|
||||
public float rollOnTurnsTorque = 20;
|
||||
|
||||
public float steerBrakingTorque = 1400;
|
||||
|
||||
public float brakingTorque;
|
||||
public float pitchCompensationTorque;
|
||||
public float rollCompensationTorque = 10;
|
||||
public float timeToFlip = 2;
|
||||
public float audioEngineSpeed;
|
||||
public float engineMinVolume = 0.5f;
|
||||
public float engineMaxVolume = 1;
|
||||
public float minAudioPitch = 0.5f;
|
||||
public float maxAudioPitch = 1.2f;
|
||||
public float maxForwardAcceleration = 20;
|
||||
public float maxReverseAcceleration = 15;
|
||||
public float maxBrakingDeceleration = 30;
|
||||
public float autoBrakingDeceleration;
|
||||
public float maxSpeed = 30;
|
||||
public AnimationCurve accelerationCurve;
|
||||
public float verticalReduction = 10;
|
||||
public float maxPitchAngle = 45;
|
||||
public Vector3 extraRigidbodyForce;
|
||||
|
||||
public float minSteerInputIdle = 0.4f;
|
||||
public float minSteerInputMoving = 0.4f;
|
||||
|
||||
[Space]
|
||||
[Header ("Hovercraft Settings")]
|
||||
[Space]
|
||||
|
||||
public List<hoverEngineSettings> hoverEngineList = new List<hoverEngineSettings> ();
|
||||
public OtherCarParts otherCarParts;
|
||||
public hoverCraftSettings settings;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool anyOnGround;
|
||||
|
||||
float audioPower = 0;
|
||||
float maxEnginePower;
|
||||
|
||||
float resetTimer;
|
||||
|
||||
float steerInput;
|
||||
float forwardInput;
|
||||
|
||||
float originalJumpPower;
|
||||
int i;
|
||||
int collisionForceLimit = 5;
|
||||
|
||||
bool rotating;
|
||||
|
||||
float leftInput = 0;
|
||||
float rightInput = 0;
|
||||
|
||||
float currentMinSteerInput;
|
||||
|
||||
hoverEngineSettings currentEngine;
|
||||
|
||||
int hoverEngineListCount;
|
||||
|
||||
ParticleSystem currentParticleSystem;
|
||||
|
||||
protected override void InitializeAudioElements ()
|
||||
{
|
||||
otherCarParts.InitializeAudioElements ();
|
||||
}
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
|
||||
}
|
||||
|
||||
public override void Start ()
|
||||
{
|
||||
base.Start ();
|
||||
|
||||
hoverEngineListCount = hoverEngineList.Count;
|
||||
|
||||
//get the boost particles inside the vehicle
|
||||
for (i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
if (otherCarParts.boostingParticles [i].gameObject.activeSelf) {
|
||||
otherCarParts.boostingParticles [i].gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < hoverEngineList.Count; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
currentEngine.hasTurbine = currentEngine.turbine != null;
|
||||
|
||||
currentEngine.hasParticles = currentEngine.ParticleSystem != null;
|
||||
}
|
||||
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, false, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, false, false);
|
||||
|
||||
originalJumpPower = vehicleControllerSettings.jumpPower;
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
base.vehicleUpdate ();
|
||||
|
||||
|
||||
maxEnginePower = 0;
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.maxEnginePower > maxEnginePower) {
|
||||
maxEnginePower = currentEngine.maxEnginePower;
|
||||
}
|
||||
|
||||
//configure every particle system according to the engine state
|
||||
float rpm = Mathf.Lerp (currentEngine.minRPM, currentEngine.maxRPM, currentEngine.maxEnginePower);
|
||||
|
||||
if (currentEngine.hasTurbine) {
|
||||
currentEngine.turbine.transform.Rotate (0, rpm * Time.deltaTime * 6, 0);
|
||||
}
|
||||
|
||||
if (currentEngine.hasParticles) {
|
||||
var hoverEngineParticleEmission = currentEngine.ParticleSystem.emission;
|
||||
hoverEngineParticleEmission.rateOverTime = currentEngine.maxEmission * currentEngine.maxEnginePower;
|
||||
|
||||
currentEngine.ParticleSystem.transform.position =
|
||||
currentEngine.hit.point + currentEngine.dustHeight * currentEngine.hit.normal;
|
||||
|
||||
currentEngine.ParticleSystem.transform.LookAt (currentEngine.hit.point + 10 * currentEngine.hit.normal);
|
||||
}
|
||||
}
|
||||
|
||||
audioPower = Mathf.Lerp (maxEnginePower, motorInput, audioEngineSpeed);
|
||||
|
||||
otherCarParts.engineAudio.volume = Mathf.Lerp (engineMinVolume, engineMaxVolume, audioPower);
|
||||
otherCarParts.engineAudio.pitch = Mathf.Lerp (minAudioPitch, maxAudioPitch, audioPower);
|
||||
|
||||
if (Mathf.Abs (horizontalAxis) > 0.05f) {
|
||||
steerInput = Mathf.Lerp (steerInput, horizontalAxis, Time.deltaTime * 10);
|
||||
} else {
|
||||
steerInput = Mathf.Lerp (steerInput, horizontalAxis, Time.deltaTime * 10);
|
||||
}
|
||||
|
||||
if (Mathf.Abs (motorInput) > 0.05f) {
|
||||
forwardInput = Mathf.Lerp (forwardInput, motorInput, Time.deltaTime * 10);
|
||||
} else {
|
||||
forwardInput = Mathf.Lerp (forwardInput, motorInput, Time.deltaTime * 10);
|
||||
}
|
||||
|
||||
float left = 0;
|
||||
float right = 0;
|
||||
|
||||
if ((forwardInput > 0.05f || forwardInput < -0.05f) && (steerInput < 0.05f && steerInput > -0.05f)) {
|
||||
left = right = forwardInput;
|
||||
//print("moving forward or backward");
|
||||
} else if (forwardInput > 0.05f && steerInput > 0) {
|
||||
left = forwardInput;
|
||||
right = -steerInput;
|
||||
//print("moving forward and to the right");
|
||||
} else if (forwardInput > 0.05f && steerInput < 0) {
|
||||
left = steerInput;
|
||||
right = forwardInput;
|
||||
//print("moving forward and to the left");
|
||||
} else if ((forwardInput < 0.05f && forwardInput > -0.05f) && steerInput > 0) {
|
||||
left = 0;
|
||||
right = steerInput;
|
||||
//print("moving to the right");
|
||||
} else if ((forwardInput < 0.05f && forwardInput > -0.05f) && steerInput < 0) {
|
||||
left = -steerInput;
|
||||
right = 0;
|
||||
//print("moving to the left");
|
||||
} else if (forwardInput < -0.05f && steerInput > 0) {
|
||||
left = 0;
|
||||
right = -steerInput;
|
||||
//print("moving backward and to the right");
|
||||
} else if (forwardInput < -0.05f && steerInput < 0) {
|
||||
left = steerInput;
|
||||
right = 0;
|
||||
//print("moving backward and to the left");
|
||||
}
|
||||
|
||||
leftInput = Mathf.Lerp (leftInput, left, Time.deltaTime * 10);
|
||||
rightInput = Mathf.Lerp (rightInput, right, Time.deltaTime * 10);
|
||||
|
||||
Vector3 rightHandLebarEuler = otherCarParts.rightHandLebar.transform.localEulerAngles;
|
||||
Vector3 lefttHandLebarEuler = otherCarParts.leftHandLebar.transform.localEulerAngles;
|
||||
|
||||
otherCarParts.rightHandLebar.transform.localRotation = Quaternion.Euler (settings.steerAngleLimit * rightInput * 2, rightHandLebarEuler.y, rightHandLebarEuler.z);
|
||||
otherCarParts.leftHandLebar.transform.localRotation = Quaternion.Euler (settings.steerAngleLimit * leftInput * 2, lefttHandLebarEuler.y, lefttHandLebarEuler.z);
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
if (currentSpeed < 5) {
|
||||
//check the current rotation of the vehicle with respect to the normal of the gravity normal component, which always point the up direction
|
||||
float angle = Vector3.Angle (currentNormal, transform.up);
|
||||
|
||||
if (angle > 60 && !rotating) {
|
||||
|
||||
resetTimer += Time.deltaTime;
|
||||
|
||||
if (resetTimer > timeToFlip) {
|
||||
resetTimer = 0;
|
||||
|
||||
StartCoroutine (rotateVehicle ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
currentSpeed = mainRigidbody.linearVelocity.magnitude;
|
||||
|
||||
if (usingHoverBoardWaypoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
//apply turn
|
||||
if (Mathf.Approximately (horizontalAxis, 0)) {
|
||||
float localR = Vector3.Dot (mainRigidbody.angularVelocity, transform.up);
|
||||
mainRigidbody.AddRelativeTorque (0, -localR * steerBrakingTorque, 0);
|
||||
} else {
|
||||
float targetRoll = -rollOnTurns * horizontalAxis;
|
||||
float roll = Mathf.Asin (transform.right.y) * Mathf.Rad2Deg;
|
||||
|
||||
if (Mathf.Abs (roll) > Mathf.Abs (targetRoll)) {
|
||||
roll = 0;
|
||||
} else {
|
||||
roll = Mathf.DeltaAngle (roll, targetRoll);
|
||||
}
|
||||
|
||||
mainRigidbody.AddRelativeTorque (0, horizontalAxis * maxSteeringTorque, roll * rollOnTurnsTorque);
|
||||
}
|
||||
|
||||
if (!usingGravityControl && !jumpInputPressed) {
|
||||
Vector3 localVelocity = transform.InverseTransformDirection (mainRigidbody.linearVelocity);
|
||||
Vector3 extraForce = Vector3.Scale (localVelocity, extraRigidbodyForce);
|
||||
|
||||
mainRigidbody.AddRelativeForce (mainRigidbody.mass * (-extraForce));
|
||||
|
||||
Vector3 gravityForce = (9.8f * currentNormal).normalized;
|
||||
|
||||
//use every engine to keep the vehicle in the air
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
//if the current engine is the main engine
|
||||
if (!currentEngine.mainEngine) {
|
||||
//find force direction by rotating local up vector towards world up
|
||||
Vector3 engineUp = currentEngine.engineTransform.up;
|
||||
|
||||
Vector3 enginePosition = currentEngine.engineTransform.position;
|
||||
|
||||
engineUp = Vector3.RotateTowards (engineUp, gravityForce, currentEngine.maxEngineAngle * Mathf.Deg2Rad, 1);
|
||||
|
||||
//check if the vehicle is on ground
|
||||
currentEngine.maxEnginePower = 0;
|
||||
|
||||
if (Physics.Raycast (enginePosition, -engineUp, out currentEngine.hit, currentEngine.maxHeight, settings.layer)) {
|
||||
//calculate down force
|
||||
currentEngine.maxEnginePower = Mathf.Pow ((currentEngine.maxHeight - currentEngine.hit.distance) / currentEngine.maxHeight, currentEngine.Exponent);
|
||||
|
||||
float force = currentEngine.maxEnginePower * currentEngine.engineForce;
|
||||
|
||||
float velocityUp = Vector3.Dot (mainRigidbody.GetPointVelocity (enginePosition), engineUp);
|
||||
|
||||
float drag = -velocityUp * Mathf.Abs (velocityUp) * currentEngine.damping;
|
||||
|
||||
mainRigidbody.AddForceAtPosition ((force + drag) * engineUp, enginePosition);
|
||||
}
|
||||
} else {
|
||||
//find current local pitch and roll
|
||||
|
||||
float pitch = Mathf.Asin (Vector3.Dot (transform.forward, gravityForce)) * Mathf.Rad2Deg;
|
||||
|
||||
float roll = Mathf.Asin (Vector3.Dot (transform.right, gravityForce)) * Mathf.Rad2Deg;
|
||||
|
||||
pitch = Mathf.DeltaAngle (pitch, 0);
|
||||
|
||||
roll = Mathf.DeltaAngle (roll, 0);
|
||||
|
||||
//apply compensation torque
|
||||
float auxPitch = -pitch * pitchCompensationTorque;
|
||||
|
||||
float auxRoll = roll * rollCompensationTorque;
|
||||
|
||||
if (!anyOnGround) {
|
||||
auxPitch *= 0.5f;
|
||||
auxRoll *= 0.5f;
|
||||
}
|
||||
|
||||
mainRigidbody.AddRelativeTorque (pitch, 0, auxRoll);
|
||||
}
|
||||
}
|
||||
|
||||
bool brakeActive = (braking || isBrakeActive ());
|
||||
|
||||
if (brakeActive) {
|
||||
float localR = Vector3.Dot (mainRigidbody.angularVelocity, transform.up);
|
||||
|
||||
mainRigidbody.AddRelativeTorque (0, -localR * brakingTorque, 0);
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.mainEngine) {
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, Vector3.zero, Time.deltaTime);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (currentEngine.mainEngine) {
|
||||
float movementMultiplier = settings.inAirMovementMultiplier;
|
||||
|
||||
if (Physics.Raycast (currentEngine.engineTransform.position, -transform.up, out currentEngine.hit, currentEngine.maxHeight, settings.layer)) {
|
||||
movementMultiplier = 1;
|
||||
}
|
||||
|
||||
//current speed along forward axis
|
||||
float speed = Vector3.Dot (mainRigidbody.linearVelocity, transform.forward);
|
||||
|
||||
//if the vehicle doesn't move by input, apply automatic brake
|
||||
bool isAutoBraking = Mathf.Approximately (motorInput, 0) && autoBrakingDeceleration > 0;
|
||||
|
||||
float thrust = motorInput;
|
||||
|
||||
if (isAutoBraking) {
|
||||
thrust = -Mathf.Sign (speed) * autoBrakingDeceleration / maxBrakingDeceleration;
|
||||
}
|
||||
|
||||
//check if it is braking, for example speed and thrust have opposing signs
|
||||
bool isBraking = speed * motorInput < 0;
|
||||
|
||||
//don't apply force if speed is max already
|
||||
if (Mathf.Abs (speed) < maxSpeed || isBraking) {
|
||||
//position on speed curve
|
||||
float normSpeed = Mathf.Sign (motorInput) * speed / maxSpeed;
|
||||
|
||||
//apply acceleration curve and select proper maximum value
|
||||
float acc = accelerationCurve.Evaluate (normSpeed) * (isBraking ? maxBrakingDeceleration : thrust > 0 ? maxForwardAcceleration : maxReverseAcceleration);
|
||||
|
||||
//drag should be added to the acceleration
|
||||
float sdd = speed * extraRigidbodyForce.z;
|
||||
float dragForce = sdd + mainRigidbody.linearDamping * speed;
|
||||
float force = acc * thrust + dragForce;
|
||||
|
||||
//reduce acceleration if the vehicle is close to vertical orientation and is trrying to go higher
|
||||
float y = Vector3.Dot (transform.forward, gravityForce);
|
||||
|
||||
if (maxPitchAngle < 90 && y * thrust > 0) {
|
||||
if (!isAutoBraking) {
|
||||
float pitch2 = Mathf.Asin (Mathf.Abs (y)) * Mathf.Rad2Deg;
|
||||
|
||||
if (pitch2 > maxPitchAngle) {
|
||||
float reduction = (pitch2 - maxPitchAngle) / (90 - maxPitchAngle) * verticalReduction;
|
||||
force /= 1 + reduction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce ((boostInput * movementMultiplier * force) * transform.forward, ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//set the exhaust particles state
|
||||
for (i = 0; i < otherCarParts.normalExhaust.Count; i++) {
|
||||
if (isTurnedOn && currentSpeed < 20) {
|
||||
if (!otherCarParts.normalExhaust [i].isPlaying) {
|
||||
otherCarParts.normalExhaust [i].Play ();
|
||||
}
|
||||
} else {
|
||||
if (otherCarParts.normalExhaust [i].isPlaying) {
|
||||
otherCarParts.normalExhaust [i].Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < otherCarParts.heavyExhaust.Count; i++) {
|
||||
if (isTurnedOn && currentSpeed > 10 && motorInput > 0.1f) {
|
||||
if (!otherCarParts.heavyExhaust [i].isPlaying) {
|
||||
otherCarParts.heavyExhaust [i].Play ();
|
||||
}
|
||||
} else {
|
||||
if (otherCarParts.heavyExhaust [i].isPlaying) {
|
||||
otherCarParts.heavyExhaust [i].Stop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
anyOnGround = true;
|
||||
|
||||
int totalWheelsOnAir = 0;
|
||||
|
||||
for (i = 0; i < hoverEngineListCount; i++) {
|
||||
currentEngine = hoverEngineList [i];
|
||||
|
||||
if (!Physics.Raycast (currentEngine.engineTransform.position, -currentEngine.engineTransform.up, out currentEngine.hit,
|
||||
currentEngine.maxHeight, settings.layer)) {
|
||||
totalWheelsOnAir++;
|
||||
}
|
||||
}
|
||||
|
||||
//if the total amount of wheels in the air is equal to the number of wheel sin the vehicle, anyOnGround is false
|
||||
if (totalWheelsOnAir == hoverEngineListCount && anyOnGround) {
|
||||
anyOnGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator jumpCoroutine ()
|
||||
{
|
||||
jumpInputPressed = true;
|
||||
|
||||
yield return new WaitForSeconds (0.5f);
|
||||
|
||||
jumpInputPressed = false;
|
||||
}
|
||||
|
||||
public override void updateCameraSteerState ()
|
||||
{
|
||||
if (localLook.z < 0f) {
|
||||
localLook.x = Mathf.Sign (localLook.x);
|
||||
}
|
||||
|
||||
steering = localLook.x;
|
||||
|
||||
steering = Mathf.Clamp (steering, -1f, 1f);
|
||||
|
||||
if (axisValues.y != 0) {
|
||||
currentMinSteerInput = minSteerInputMoving;
|
||||
} else {
|
||||
currentMinSteerInput = minSteerInputIdle;
|
||||
}
|
||||
|
||||
if (Mathf.Abs (steering) > currentMinSteerInput) {
|
||||
horizontalAxis = steering;
|
||||
} else {
|
||||
horizontalAxis = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if the vehicle is using the gravity control, set the state in this component
|
||||
public override void changeGravityControlUse (bool state)
|
||||
{
|
||||
base.changeGravityControlUse (state);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
base.changeVehicleState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void setTurnOnState ()
|
||||
{
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, true, true, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, true, false);
|
||||
}
|
||||
|
||||
public override void setTurnOffState (bool previouslyTurnedOn)
|
||||
{
|
||||
base.setTurnOffState (previouslyTurnedOn);
|
||||
|
||||
if (previouslyTurnedOn) {
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, true);
|
||||
setAudioState (otherCarParts.engineEndAudioElement, 5, 1, false, true, false);
|
||||
}
|
||||
|
||||
steerInput = 0;
|
||||
}
|
||||
|
||||
public override bool isDrivingActive ()
|
||||
{
|
||||
return driving;
|
||||
}
|
||||
|
||||
public override void setEngineOnOrOffState ()
|
||||
{
|
||||
base.setEngineOnOrOffState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
{
|
||||
base.turnOnOrOff (state, previouslyTurnedOn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
//stop the audio sources
|
||||
setAudioState (otherCarParts.engineAudioElement, 5, 0, false, false, false);
|
||||
setAudioState (otherCarParts.engineStartAudioElement, 5, 0.7f, false, false, false);
|
||||
|
||||
setTurnOffState (false);
|
||||
|
||||
//disable the exhausts particles
|
||||
for (i = 0; i < otherCarParts.normalExhaust.Count; i++) {
|
||||
otherCarParts.normalExhaust [i].Stop ();
|
||||
}
|
||||
|
||||
for (i = 0; i < otherCarParts.heavyExhaust.Count; i++) {
|
||||
otherCarParts.heavyExhaust [i].Stop ();
|
||||
}
|
||||
|
||||
//disable the controller
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
//reset the vehicle rotation if it is upside down
|
||||
IEnumerator rotateVehicle ()
|
||||
{
|
||||
rotating = true;
|
||||
|
||||
Quaternion currentRotation = transform.rotation;
|
||||
|
||||
//rotate in the forward direction of the vehicle
|
||||
Quaternion dstRotPlayer = Quaternion.LookRotation (transform.forward, currentNormal);
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
transform.rotation = Quaternion.Slerp (currentRotation, dstRotPlayer, t);
|
||||
mainRigidbody.linearVelocity = Vector3.zero;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
rotating = false;
|
||||
}
|
||||
|
||||
//if the vehicle is using the boost, set the boost particles
|
||||
public override void usingBoosting ()
|
||||
{
|
||||
base.usingBoosting ();
|
||||
|
||||
for (int i = 0; i < otherCarParts.boostingParticles.Count; i++) {
|
||||
currentParticleSystem = otherCarParts.boostingParticles [i];
|
||||
|
||||
if (usingBoost) {
|
||||
if (!currentParticleSystem.isPlaying) {
|
||||
if (!currentParticleSystem.gameObject.activeSelf) {
|
||||
currentParticleSystem.gameObject.SetActive (true);
|
||||
}
|
||||
|
||||
currentParticleSystem.Play ();
|
||||
|
||||
var boostingParticlesMain = currentParticleSystem.main;
|
||||
boostingParticlesMain.loop = true;
|
||||
}
|
||||
} else {
|
||||
if (currentParticleSystem.isPlaying) {
|
||||
var boostingParticlesMain = currentParticleSystem.main;
|
||||
boostingParticlesMain.loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//use a jump platform
|
||||
public void useVehicleJumpPlatform (Vector3 direction)
|
||||
{
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * direction, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public void useJumpPlatformParable (Vector3 direction)
|
||||
{
|
||||
Vector3 jumpForce = direction;
|
||||
|
||||
mainRigidbody.AddForce (jumpForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
public void setNewJumpPower (float newJumpPower)
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = newJumpPower * 100;
|
||||
}
|
||||
|
||||
public void setOriginalJumpPower ()
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = originalJumpPower;
|
||||
}
|
||||
|
||||
public void setCanJumpState (bool state)
|
||||
{
|
||||
vehicleControllerSettings.canJump = state;
|
||||
}
|
||||
|
||||
//OVERRIDE FUNCTIONS FOR VEHICLE CONTROLLER
|
||||
|
||||
//if any collider in the vehicle collides, then
|
||||
public override void setCollisionDetected (Collision currentCollision)
|
||||
{
|
||||
//check that the collision is not with the player
|
||||
if (!currentCollision.gameObject.CompareTag ("Player")) {
|
||||
//if the velocity of the collision is higher that the limit
|
||||
if (currentCollision.relativeVelocity.magnitude > collisionForceLimit) {
|
||||
//set the collision audio with a random collision clip
|
||||
if (otherCarParts.crashAudioElements.Length > 0) {
|
||||
setAudioState (otherCarParts.crashAudioElements [UnityEngine.Random.Range (0, otherCarParts.crashAudioElements.Length)], 5, 1, false, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void startBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
braking = true;
|
||||
}
|
||||
|
||||
public override void endBrakeVehicleToStopCompletely ()
|
||||
{
|
||||
braking = false;
|
||||
}
|
||||
|
||||
public override float getCurrentSpeed ()
|
||||
{
|
||||
return currentSpeed;
|
||||
}
|
||||
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public override void inputJump ()
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && vehicleControllerSettings.canJump) {
|
||||
if (anyOnGround && !jumpInputPressed) {
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * vehicleControllerSettings.jumpPower * currentNormal, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
if (usingHoverBoardWaypoint) {
|
||||
StartCoroutine (jumpCoroutine ());
|
||||
|
||||
pickOrReleaseHoverboardVehicle (false, false);
|
||||
|
||||
Vector3 totalJumpForce = mainRigidbody.mass * hoverboardJumpForce * (currentNormal + transform.forward);
|
||||
|
||||
if (useHoverboardJumpClamp) {
|
||||
totalJumpForce = Vector3.ClampMagnitude (totalJumpForce, hoverboardJumpClamp);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalJumpForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseTurbo (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && !usingHoverBoardWaypoint) {
|
||||
//boost input
|
||||
if (holdingButton) {
|
||||
usingBoost = true;
|
||||
|
||||
//set the camera move away action
|
||||
mainVehicleCameraController.usingBoost (true, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
} else {
|
||||
//stop boost
|
||||
usingBoost = false;
|
||||
|
||||
//disable the camera move away action
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
|
||||
//disable the boost particles
|
||||
usingBoosting ();
|
||||
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputSetTurnOnState ()
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
if (mainVehicleHUDManager.canSetTurnOnState) {
|
||||
setEngineOnOrOffState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHorn ()
|
||||
{
|
||||
if (driving) {
|
||||
setAudioState (otherCarParts.hornAudioElement, 5, 1, false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseBrake (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
braking = holdingButton;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class hoverEngineSettings
|
||||
{
|
||||
public string Name;
|
||||
public Transform engineTransform;
|
||||
public ParticleSystem ParticleSystem;
|
||||
|
||||
|
||||
public float maxEmission = 250;
|
||||
public float dustHeight = 0.1f;
|
||||
public float maxHeight = 2;
|
||||
public float engineForce = 4000;
|
||||
public float damping = 150;
|
||||
public float Exponent = 2;
|
||||
public float maxEngineAngle = 10;
|
||||
public bool mainEngine;
|
||||
public float minRPM = 100;
|
||||
public float maxRPM = 150;
|
||||
public Transform turbine;
|
||||
[HideInInspector] public RaycastHit hit;
|
||||
[HideInInspector] public float maxEnginePower;
|
||||
|
||||
[HideInInspector] public bool hasTurbine;
|
||||
[HideInInspector] public bool hasParticles;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class OtherCarParts
|
||||
{
|
||||
public Transform rightHandLebar;
|
||||
public Transform leftHandLebar;
|
||||
public Transform COM;
|
||||
public GameObject chassis;
|
||||
public AudioClip engineStartClip;
|
||||
public AudioElement engineStartAudioElement;
|
||||
public AudioClip engineClip;
|
||||
public AudioElement engineAudioElement;
|
||||
public AudioClip engineEndClip;
|
||||
public AudioElement engineEndAudioElement;
|
||||
public AudioClip[] crashClips;
|
||||
public AudioElement[] crashAudioElements;
|
||||
public AudioClip hornClip;
|
||||
public AudioElement hornAudioElement;
|
||||
public List<ParticleSystem> normalExhaust = new List<ParticleSystem> ();
|
||||
public List<ParticleSystem> heavyExhaust = new List<ParticleSystem> ();
|
||||
public AudioSource engineStartAudio;
|
||||
public AudioSource engineAudio;
|
||||
public AudioSource crashAudio;
|
||||
public AudioSource hornAudio;
|
||||
public List<ParticleSystem> boostingParticles = new List<ParticleSystem> ();
|
||||
|
||||
public void InitializeAudioElements ()
|
||||
{
|
||||
if (engineStartClip != null) {
|
||||
engineStartAudioElement.clip = engineStartClip;
|
||||
}
|
||||
|
||||
if (engineClip != null) {
|
||||
engineAudioElement.clip = engineClip;
|
||||
}
|
||||
|
||||
if (engineEndClip != null) {
|
||||
engineEndAudioElement.clip = engineEndClip;
|
||||
}
|
||||
|
||||
if (crashClips != null && crashClips.Length > 0) {
|
||||
crashAudioElements = new AudioElement[crashClips.Length];
|
||||
|
||||
for (var i = 0; i < crashClips.Length; i++) {
|
||||
crashAudioElements [i] = new AudioElement { clip = crashClips [i] };
|
||||
}
|
||||
}
|
||||
|
||||
if (hornClip != null) {
|
||||
hornAudioElement.clip = hornClip;
|
||||
}
|
||||
|
||||
if (engineStartAudio != null) {
|
||||
engineStartAudioElement.audioSource = engineStartAudio;
|
||||
}
|
||||
|
||||
if (engineAudio != null) {
|
||||
engineAudioElement.audioSource = engineAudio;
|
||||
engineEndAudioElement.audioSource = engineAudio;
|
||||
}
|
||||
|
||||
if (crashAudio != null) {
|
||||
foreach (var audioElement in crashAudioElements) {
|
||||
audioElement.audioSource = crashAudio;
|
||||
}
|
||||
}
|
||||
|
||||
if (hornAudio != null) {
|
||||
hornAudioElement.audioSource = hornAudio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class hoverCraftSettings
|
||||
{
|
||||
public LayerMask layer;
|
||||
public float steerAngleLimit;
|
||||
[Range (0, 1)] public float inAirMovementMultiplier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3012a06fc1d64e4db106fd9b566f13d
|
||||
timeCreated: 1467570608
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/hoverCraftController.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a5ada0305af8104294c0d59da8b3de8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/motorBikeController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,981 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class sphereController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public otherVehicleParts vehicleParts;
|
||||
public vehicleSettings settings;
|
||||
|
||||
[Space]
|
||||
[Header ("Physics Settings")]
|
||||
[Space]
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSpeed = 10f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxClimbSpeed = 4f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxBoostClimbSpeed = 4f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSwimSpeed = 5f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxAcceleration = 10f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxAirAcceleration = 1f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxClimbAcceleration = 40f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSwimAcceleration = 5f;
|
||||
|
||||
[SerializeField, Range (0, 5)]
|
||||
int maxAirJumps = 0;
|
||||
|
||||
[SerializeField, Range (0, 90)]
|
||||
float maxGroundAngle = 25f, maxStairsAngle = 50f;
|
||||
|
||||
[SerializeField, Range (90, 180)]
|
||||
float maxClimbAngle = 140f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSnapSpeed = 100f;
|
||||
|
||||
[SerializeField]
|
||||
float probeDistance = 1f;
|
||||
|
||||
[SerializeField]
|
||||
float submergenceOffset = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
float submergenceRange = 1f;
|
||||
|
||||
[SerializeField]
|
||||
float buoyancy = 1f;
|
||||
|
||||
[SerializeField, Range (0f, 10f)]
|
||||
float waterDrag = 1f;
|
||||
|
||||
[SerializeField, Range (0.01f, 1f)]
|
||||
float swimThreshold = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
LayerMask probeMask = -1, stairsMask = -1, climbMask = -1, waterMask = 0;
|
||||
|
||||
[SerializeField]
|
||||
float sphereRadius = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
float sphereAlignSpeed = 45;
|
||||
|
||||
[SerializeField]
|
||||
float sphereAirRotation = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
float sphereSwimRotation = 2f;
|
||||
|
||||
public bool useClimbEnabled = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool anyOnGround;
|
||||
|
||||
public int stepsSinceLastJump;
|
||||
|
||||
public int climbContactCount;
|
||||
|
||||
public bool desiresClimbing;
|
||||
|
||||
public int groundContactCount;
|
||||
|
||||
public int steepContactCount;
|
||||
|
||||
public int stepsSinceLastGrounded;
|
||||
|
||||
public Vector3 velocity;
|
||||
|
||||
public Vector3 moveInput;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform sphereTransform;
|
||||
|
||||
float originalJumpPower;
|
||||
|
||||
Transform vehicleCameraTransform;
|
||||
|
||||
Rigidbody connectedBody;
|
||||
Rigidbody previousConnectedBody;
|
||||
|
||||
Vector3 connectionVelocity;
|
||||
|
||||
Vector3 connectionWorldPosition;
|
||||
Vector3 connectionLocalPosition;
|
||||
|
||||
Vector3 upAxis, rightAxis, forwardAxis;
|
||||
|
||||
bool desiredJump;
|
||||
|
||||
Vector3 contactNormal, steepNormal, climbNormal, lastClimbNormal;
|
||||
|
||||
Vector3 lastContactNormal, lastSteepNormal, lastConnectionVelocity;
|
||||
|
||||
float submergence;
|
||||
|
||||
int jumpPhase;
|
||||
|
||||
float minGroundDotProduct, minStairsDotProduct, minClimbDotProduct;
|
||||
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
|
||||
OnValidate ();
|
||||
}
|
||||
|
||||
public override void Start ()
|
||||
{
|
||||
base.Start ();
|
||||
|
||||
originalJumpPower = vehicleControllerSettings.jumpPower;
|
||||
|
||||
vehicleCameraTransform = mainVehicleCameraController.transform;
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
base.vehicleUpdate ();
|
||||
|
||||
if (isPlayerMovingOn3dWorld ()) {
|
||||
moveInput.x = horizontalAxis;
|
||||
moveInput.z = verticalAxis;
|
||||
} else {
|
||||
if (desiresClimbing) {
|
||||
moveInput.z = verticalAxis;
|
||||
|
||||
moveInput.x = 0;
|
||||
} else {
|
||||
moveInput.x = verticalAxis;
|
||||
moveInput.z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
moveInput.y = 0;
|
||||
moveInput = Vector3.ClampMagnitude (moveInput, 1f);
|
||||
|
||||
if (isCameraTypeFree ()) {
|
||||
rightAxis = projectDirectionOnPlane (settings.vehicleCamera.transform.right, upAxis);
|
||||
|
||||
forwardAxis = projectDirectionOnPlane (settings.vehicleCamera.transform.forward, upAxis);
|
||||
} else {
|
||||
Transform currentLockedCameraTransform = mainVehicleCameraController.getLockedCameraTransform ();
|
||||
|
||||
if (currentLockedCameraTransform != null) {
|
||||
if (isPlayerMovingOn3dWorld ()) {
|
||||
rightAxis = projectDirectionOnPlane (currentLockedCameraTransform.right, upAxis);
|
||||
|
||||
forwardAxis = projectDirectionOnPlane (currentLockedCameraTransform.forward, upAxis);
|
||||
} else {
|
||||
rightAxis = projectDirectionOnPlane (currentLockedCameraTransform.right, upAxis);
|
||||
|
||||
forwardAxis = projectDirectionOnPlane (currentLockedCameraTransform.forward, upAxis);
|
||||
}
|
||||
} else {
|
||||
rightAxis = Vector3.zero;
|
||||
|
||||
forwardAxis = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSwimmingActive ()) {
|
||||
setDesiresClimbingState (false);
|
||||
}
|
||||
|
||||
updateSphereState ();
|
||||
}
|
||||
|
||||
void setDesiresClimbingState (bool state)
|
||||
{
|
||||
desiresClimbing = state;
|
||||
|
||||
if (desiresClimbing) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
mainVehicleGravityControl.setGravityForcePausedState (desiresClimbing);
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
anyOnGround = isOnGround ();
|
||||
|
||||
if (usingHoverBoardWaypoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
upAxis = mainVehicleGravityControl.getCurrentNormal ();
|
||||
|
||||
Vector3 gravity = -upAxis * mainVehicleGravityControl.getGravityForce ();
|
||||
|
||||
fixedUpdateSphereState ();
|
||||
|
||||
if (insideWater ()) {
|
||||
velocity *= 1f - waterDrag * submergence * Time.deltaTime;
|
||||
}
|
||||
|
||||
adjustVelocity ();
|
||||
|
||||
if (desiredJump) {
|
||||
desiredJump = false;
|
||||
|
||||
activeJump (gravity);
|
||||
}
|
||||
|
||||
if (isClimbingActive ()) {
|
||||
velocity -= contactNormal * (maxClimbAcceleration * 0.9f * Time.deltaTime);
|
||||
|
||||
} else if (insideWater ()) {
|
||||
velocity += gravity * ((1f - buoyancy * submergence) * Time.deltaTime);
|
||||
|
||||
} else if (isOnGround () && velocity.sqrMagnitude < 0.01f) {
|
||||
velocity += contactNormal * (Vector3.Dot (gravity, contactNormal) * Time.deltaTime);
|
||||
|
||||
} else if (desiresClimbing && isOnGround ()) {
|
||||
velocity += (gravity - contactNormal * (maxClimbAcceleration * 0.9f)) * Time.deltaTime;
|
||||
|
||||
} else {
|
||||
velocity += gravity * Time.deltaTime;
|
||||
|
||||
}
|
||||
|
||||
mainRigidbody.linearVelocity = velocity;
|
||||
|
||||
if (anyOnGround || isClimbingActive ()) {
|
||||
bool brakeActive = (braking || isBrakeActive ());
|
||||
|
||||
if (brakeActive) {
|
||||
float verticalVelocity = vehicleCameraTransform.InverseTransformDirection (mainRigidbody.linearVelocity).y;
|
||||
Vector3 downVelocity = vehicleCameraTransform.up * verticalVelocity;
|
||||
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, Vector3.zero + downVelocity, Time.deltaTime * settings.brakeForce);
|
||||
}
|
||||
}
|
||||
|
||||
clearState ();
|
||||
|
||||
currentSpeed = mainRigidbody.linearVelocity.magnitude;
|
||||
}
|
||||
|
||||
void updateSphereState ()
|
||||
{
|
||||
Vector3 rotationPlaneNormal = lastContactNormal;
|
||||
|
||||
float rotationFactor = 1f;
|
||||
|
||||
if (isClimbingActive ()) {
|
||||
|
||||
} else if (isSwimmingActive ()) {
|
||||
|
||||
rotationFactor = sphereSwimRotation;
|
||||
} else if (!isOnGround ()) {
|
||||
if (isOnSteep ()) {
|
||||
rotationPlaneNormal = lastSteepNormal;
|
||||
} else {
|
||||
rotationFactor = sphereAirRotation;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 movement = (mainRigidbody.linearVelocity - lastConnectionVelocity) * Time.deltaTime;
|
||||
|
||||
movement -= rotationPlaneNormal * Vector3.Dot (movement, rotationPlaneNormal);
|
||||
|
||||
float distance = movement.magnitude;
|
||||
|
||||
Quaternion rotation = sphereTransform.localRotation;
|
||||
|
||||
if (connectedBody != null && connectedBody == previousConnectedBody) {
|
||||
rotation = Quaternion.Euler (connectedBody.angularVelocity * (Mathf.Rad2Deg * Time.deltaTime)) * rotation;
|
||||
|
||||
if (distance < 0.001f) {
|
||||
sphereTransform.localRotation = rotation;
|
||||
|
||||
return;
|
||||
}
|
||||
} else if (distance < 0.001f) {
|
||||
return;
|
||||
}
|
||||
|
||||
float angle = distance * rotationFactor * (180f / Mathf.PI) / sphereRadius;
|
||||
|
||||
Vector3 rotationAxis = Vector3.Cross (rotationPlaneNormal, movement).normalized;
|
||||
|
||||
rotation = Quaternion.Euler (rotationAxis * angle) * rotation;
|
||||
|
||||
if (sphereAlignSpeed > 0f) {
|
||||
rotation = alignSphereRotation (rotationAxis, rotation, distance);
|
||||
}
|
||||
|
||||
sphereTransform.localRotation = rotation;
|
||||
}
|
||||
|
||||
Quaternion alignSphereRotation (Vector3 rotationAxis, Quaternion rotation, float traveledDistance)
|
||||
{
|
||||
Vector3 sphereAxis = sphereTransform.up;
|
||||
|
||||
float dot = Mathf.Clamp (Vector3.Dot (sphereAxis, rotationAxis), -1f, 1f);
|
||||
|
||||
float angle = Mathf.Acos (dot) * Mathf.Rad2Deg;
|
||||
|
||||
float maxAngle = sphereAlignSpeed * traveledDistance;
|
||||
|
||||
Quaternion newAlignment = Quaternion.FromToRotation (sphereAxis, rotationAxis) * rotation;
|
||||
|
||||
if (angle <= maxAngle) {
|
||||
return newAlignment;
|
||||
} else {
|
||||
return Quaternion.SlerpUnclamped (rotation, newAlignment, maxAngle / angle);
|
||||
}
|
||||
}
|
||||
|
||||
void clearState ()
|
||||
{
|
||||
lastContactNormal = contactNormal;
|
||||
|
||||
lastSteepNormal = steepNormal;
|
||||
|
||||
lastConnectionVelocity = connectionVelocity;
|
||||
|
||||
groundContactCount = steepContactCount = climbContactCount = 0;
|
||||
|
||||
contactNormal = steepNormal = climbNormal = Vector3.zero;
|
||||
|
||||
connectionVelocity = Vector3.zero;
|
||||
|
||||
previousConnectedBody = connectedBody;
|
||||
|
||||
connectedBody = null;
|
||||
|
||||
submergence = 0f;
|
||||
}
|
||||
|
||||
void fixedUpdateSphereState ()
|
||||
{
|
||||
stepsSinceLastGrounded += 1;
|
||||
|
||||
stepsSinceLastJump += 1;
|
||||
|
||||
velocity = mainRigidbody.linearVelocity;
|
||||
|
||||
if (checkClimbing () ||
|
||||
checkSwimming () ||
|
||||
isOnGround () ||
|
||||
snapToGround () ||
|
||||
checkSteepContacts ()) {
|
||||
|
||||
stepsSinceLastGrounded = 0;
|
||||
|
||||
if (stepsSinceLastJump > 1) {
|
||||
jumpPhase = 0;
|
||||
}
|
||||
|
||||
if (groundContactCount > 1) {
|
||||
contactNormal.Normalize ();
|
||||
}
|
||||
} else {
|
||||
contactNormal = upAxis;
|
||||
}
|
||||
|
||||
if (connectedBody != null) {
|
||||
if (connectedBody.isKinematic || connectedBody.mass >= mainRigidbody.mass) {
|
||||
updateConnectionState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateConnectionState ()
|
||||
{
|
||||
if (connectedBody == previousConnectedBody) {
|
||||
Vector3 connectionMovement = connectedBody.transform.TransformPoint (connectionLocalPosition) - connectionWorldPosition;
|
||||
|
||||
connectionVelocity = connectionMovement / Time.deltaTime;
|
||||
}
|
||||
|
||||
connectionWorldPosition = mainRigidbody.position;
|
||||
|
||||
connectionLocalPosition = connectedBody.transform.InverseTransformPoint (connectionWorldPosition);
|
||||
}
|
||||
|
||||
bool checkClimbing ()
|
||||
{
|
||||
if (isClimbingActive ()) {
|
||||
if (climbContactCount > 1) {
|
||||
climbNormal.Normalize ();
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, climbNormal);
|
||||
|
||||
if (upDot >= minGroundDotProduct) {
|
||||
climbNormal = lastClimbNormal;
|
||||
}
|
||||
}
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = climbNormal;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkSwimming ()
|
||||
{
|
||||
if (isSwimmingActive ()) {
|
||||
groundContactCount = 0;
|
||||
|
||||
contactNormal = upAxis;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void updateMovingState ()
|
||||
{
|
||||
moving = verticalAxis != 0 || horizontalAxis != 0;
|
||||
}
|
||||
|
||||
bool snapToGround ()
|
||||
{
|
||||
if (stepsSinceLastGrounded > 1 || stepsSinceLastJump <= 2 || insideWater ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float speed = velocity.magnitude;
|
||||
|
||||
if (speed > maxSnapSpeed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
if (!Physics.Raycast (mainRigidbody.position, -upAxis, out hit, probeDistance, probeMask, QueryTriggerInteraction.Ignore)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 hitNormal = hit.normal;
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, hitNormal);
|
||||
|
||||
if (upDot < getMinDot (hit.collider.gameObject.layer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = hitNormal;
|
||||
|
||||
float dot = Vector3.Dot (velocity, hitNormal);
|
||||
|
||||
if (dot > 0f) {
|
||||
velocity = (velocity - hitNormal * dot).normalized * speed;
|
||||
}
|
||||
|
||||
connectedBody = hit.rigidbody;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkSteepContacts ()
|
||||
{
|
||||
if (steepContactCount > 1) {
|
||||
steepNormal.Normalize ();
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, steepNormal);
|
||||
|
||||
if (upDot >= minGroundDotProduct) {
|
||||
steepContactCount = 0;
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = steepNormal;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void adjustVelocity ()
|
||||
{
|
||||
float acceleration, speed;
|
||||
|
||||
Vector3 xAxis, zAxis;
|
||||
|
||||
float currentMaxSpeeed = maxSpeed * boostInput;
|
||||
|
||||
if (isClimbingActive ()) {
|
||||
acceleration = maxClimbAcceleration;
|
||||
|
||||
speed = maxClimbSpeed;
|
||||
|
||||
if (usingBoost) {
|
||||
speed = maxBoostClimbSpeed;
|
||||
}
|
||||
|
||||
xAxis = Vector3.Cross (contactNormal, upAxis);
|
||||
|
||||
zAxis = upAxis;
|
||||
} else if (insideWater ()) {
|
||||
float swimFactor = Mathf.Min (1f, submergence / swimThreshold);
|
||||
|
||||
acceleration = Mathf.LerpUnclamped (isOnGround () ? maxAcceleration : maxAirAcceleration, maxSwimAcceleration, swimFactor);
|
||||
|
||||
speed = Mathf.LerpUnclamped (currentMaxSpeeed, maxSwimSpeed, swimFactor);
|
||||
|
||||
xAxis = rightAxis;
|
||||
zAxis = forwardAxis;
|
||||
} else {
|
||||
acceleration = isOnGround () ? maxAcceleration : maxAirAcceleration;
|
||||
|
||||
float currentClimbSpeed = maxClimbSpeed;
|
||||
|
||||
if (usingBoost) {
|
||||
currentClimbSpeed = maxBoostClimbSpeed;
|
||||
}
|
||||
|
||||
speed = isOnGround () && desiresClimbing ? currentClimbSpeed : currentMaxSpeeed;
|
||||
|
||||
xAxis = rightAxis;
|
||||
zAxis = forwardAxis;
|
||||
}
|
||||
|
||||
xAxis = projectDirectionOnPlane (xAxis, contactNormal);
|
||||
zAxis = projectDirectionOnPlane (zAxis, contactNormal);
|
||||
|
||||
Vector3 relativeVelocity = velocity - connectionVelocity;
|
||||
|
||||
Vector3 adjustment;
|
||||
|
||||
adjustment.x = moveInput.x * speed - Vector3.Dot (relativeVelocity, xAxis);
|
||||
adjustment.z = moveInput.z * speed - Vector3.Dot (relativeVelocity, zAxis);
|
||||
|
||||
adjustment.y = isSwimmingActive () ? moveInput.y * speed - Vector3.Dot (relativeVelocity, upAxis) : 0f;
|
||||
|
||||
adjustment = Vector3.ClampMagnitude (adjustment, acceleration * Time.deltaTime);
|
||||
|
||||
velocity += (xAxis * adjustment.x + zAxis * adjustment.z) * boostInput;
|
||||
|
||||
if (isSwimmingActive ()) {
|
||||
velocity += upAxis * adjustment.y;
|
||||
}
|
||||
}
|
||||
|
||||
bool isOnGround ()
|
||||
{
|
||||
return groundContactCount > 0;
|
||||
}
|
||||
|
||||
bool isOnSteep ()
|
||||
{
|
||||
return steepContactCount > 0;
|
||||
}
|
||||
|
||||
bool isClimbingActive ()
|
||||
{
|
||||
return climbContactCount > 0 && stepsSinceLastJump > 2;
|
||||
}
|
||||
|
||||
bool insideWater ()
|
||||
{
|
||||
return submergence > 0f;
|
||||
}
|
||||
|
||||
bool isSwimmingActive ()
|
||||
{
|
||||
return submergence >= swimThreshold;
|
||||
}
|
||||
|
||||
public void preventSnapToGround ()
|
||||
{
|
||||
stepsSinceLastJump = -1;
|
||||
}
|
||||
|
||||
void OnValidate ()
|
||||
{
|
||||
minGroundDotProduct = Mathf.Cos (maxGroundAngle * Mathf.Deg2Rad);
|
||||
|
||||
minStairsDotProduct = Mathf.Cos (maxStairsAngle * Mathf.Deg2Rad);
|
||||
|
||||
minClimbDotProduct = Mathf.Cos (maxClimbAngle * Mathf.Deg2Rad);
|
||||
}
|
||||
|
||||
void activeJump (Vector3 gravity)
|
||||
{
|
||||
Vector3 jumpDirection;
|
||||
|
||||
if (isOnGround ()) {
|
||||
jumpDirection = contactNormal;
|
||||
} else if (isOnSteep ()) {
|
||||
jumpDirection = steepNormal;
|
||||
|
||||
jumpPhase = 0;
|
||||
} else if (maxAirJumps > 0 && jumpPhase <= maxAirJumps) {
|
||||
if (jumpPhase == 0) {
|
||||
jumpPhase = 1;
|
||||
}
|
||||
jumpDirection = contactNormal;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
stepsSinceLastJump = 0;
|
||||
|
||||
jumpPhase += 1;
|
||||
|
||||
float jumpSpeed = Mathf.Sqrt (2f * gravity.magnitude * vehicleControllerSettings.jumpPower);
|
||||
|
||||
if (insideWater ()) {
|
||||
jumpSpeed *= Mathf.Max (0f, 1f - submergence / swimThreshold);
|
||||
}
|
||||
|
||||
jumpDirection = (jumpDirection + upAxis).normalized;
|
||||
|
||||
float alignedSpeed = Vector3.Dot (velocity, jumpDirection);
|
||||
|
||||
if (alignedSpeed > 0f) {
|
||||
jumpSpeed = Mathf.Max (jumpSpeed - alignedSpeed, 0f);
|
||||
}
|
||||
|
||||
velocity += jumpDirection * jumpSpeed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision collision)
|
||||
{
|
||||
EvaluateCollision (collision);
|
||||
}
|
||||
|
||||
void OnCollisionStay (Collision collision)
|
||||
{
|
||||
EvaluateCollision (collision);
|
||||
}
|
||||
|
||||
void EvaluateCollision (Collision collision)
|
||||
{
|
||||
if (isSwimmingActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int layer = collision.gameObject.layer;
|
||||
|
||||
float minDot = getMinDot (layer);
|
||||
|
||||
for (int i = 0; i < collision.contacts.Length; i++) {
|
||||
Vector3 normal = collision.contacts [i].normal;
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, normal);
|
||||
|
||||
if (upDot >= minDot) {
|
||||
groundContactCount += 1;
|
||||
|
||||
contactNormal += normal;
|
||||
|
||||
connectedBody = collision.rigidbody;
|
||||
} else {
|
||||
if (upDot > -0.01f) {
|
||||
steepContactCount += 1;
|
||||
|
||||
steepNormal += normal;
|
||||
|
||||
if (groundContactCount == 0) {
|
||||
connectedBody = collision.rigidbody;
|
||||
}
|
||||
}
|
||||
|
||||
if (desiresClimbing && upDot >= minClimbDotProduct && (climbMask & (1 << layer)) != 0) {
|
||||
|
||||
climbContactCount += 1;
|
||||
|
||||
climbNormal += normal;
|
||||
|
||||
lastClimbNormal = normal;
|
||||
|
||||
connectedBody = collision.rigidbody;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider other)
|
||||
{
|
||||
if ((waterMask & (1 << other.gameObject.layer)) != 0) {
|
||||
EvaluateSubmergence (other);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay (Collider other)
|
||||
{
|
||||
if ((waterMask & (1 << other.gameObject.layer)) != 0) {
|
||||
EvaluateSubmergence (other);
|
||||
}
|
||||
}
|
||||
|
||||
void EvaluateSubmergence (Collider collider)
|
||||
{
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast (mainRigidbody.position + upAxis * submergenceOffset, -upAxis, out hit, submergenceRange + 1f, waterMask)) {
|
||||
//, QueryTriggerInteraction.Collide)) {
|
||||
submergence = 1f - hit.distance / submergenceRange;
|
||||
} else {
|
||||
submergence = 1f;
|
||||
}
|
||||
|
||||
if (isSwimmingActive ()) {
|
||||
connectedBody = collider.attachedRigidbody;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 projectDirectionOnPlane (Vector3 direction, Vector3 normal)
|
||||
{
|
||||
return (direction - normal * Vector3.Dot (direction, normal)).normalized;
|
||||
}
|
||||
|
||||
float getMinDot (int layer)
|
||||
{
|
||||
if ((stairsMask & (1 << layer)) == 0) {
|
||||
return minGroundDotProduct;
|
||||
} else {
|
||||
return minStairsDotProduct;
|
||||
}
|
||||
}
|
||||
|
||||
//if the vehicle is using the gravity control, set the state in this component
|
||||
public override void changeGravityControlUse (bool state)
|
||||
{
|
||||
base.changeGravityControlUse (state);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
base.changeVehicleState ();
|
||||
|
||||
setDesiresClimbingState (false);
|
||||
}
|
||||
|
||||
public override void setTurnOnState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void setTurnOffState (bool previouslyTurnedOn)
|
||||
{
|
||||
base.setTurnOffState (previouslyTurnedOn);
|
||||
|
||||
if (previouslyTurnedOn) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override bool isDrivingActive ()
|
||||
{
|
||||
return driving;
|
||||
}
|
||||
|
||||
public override void setEngineOnOrOffState ()
|
||||
{
|
||||
base.setEngineOnOrOffState ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void turnOnOrOff (bool state, bool previouslyTurnedOn)
|
||||
{
|
||||
base.turnOnOrOff (state, previouslyTurnedOn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
base.disableVehicle ();
|
||||
|
||||
}
|
||||
|
||||
//if the vehicle is using the boost, set the boost particles
|
||||
public override void usingBoosting ()
|
||||
{
|
||||
base.usingBoosting ();
|
||||
|
||||
}
|
||||
|
||||
//use a jump platform
|
||||
public void useVehicleJumpPlatform (Vector3 direction)
|
||||
{
|
||||
mainRigidbody.AddForce (mainRigidbody.mass * direction, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public void useJumpPlatformParable (Vector3 direction)
|
||||
{
|
||||
Vector3 jumpForce = direction;
|
||||
|
||||
mainRigidbody.AddForce (jumpForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
public void setNewJumpPower (float newJumpPower)
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = newJumpPower * 100;
|
||||
}
|
||||
|
||||
public void setOriginalJumpPower ()
|
||||
{
|
||||
vehicleControllerSettings.jumpPower = originalJumpPower;
|
||||
}
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public override void inputJump ()
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && vehicleControllerSettings.canJump) {
|
||||
if (usingHoverBoardWaypoint) {
|
||||
pickOrReleaseHoverboardVehicle (false, false);
|
||||
|
||||
Vector3 totalJumpForce = mainRigidbody.mass * hoverboardJumpForce * (currentNormal + transform.forward);
|
||||
|
||||
if (useHoverboardJumpClamp) {
|
||||
totalJumpForce = Vector3.ClampMagnitude (totalJumpForce, hoverboardJumpClamp);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalJumpForce, ForceMode.Impulse);
|
||||
|
||||
transform.rotation = Quaternion.identity;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSwimmingActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (desiresClimbing) {
|
||||
if (!isClimbingActive ()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!anyOnGround) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setDesiresClimbingState (false);
|
||||
|
||||
desiredJump = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseTurbo (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && !usingHoverBoardWaypoint) {
|
||||
//boost input
|
||||
if (holdingButton) {
|
||||
if (vehicleControllerSettings.canUseBoost) {
|
||||
usingBoost = true;
|
||||
//set the camera move away action
|
||||
mainVehicleCameraController.usingBoost (true, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
}
|
||||
} else {
|
||||
//stop boost input
|
||||
usingBoost = false;
|
||||
|
||||
//disable the camera move away action
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
|
||||
usingBoosting ();
|
||||
|
||||
boostInput = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputHoldOrReleaseBrake (bool holdingButton)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn && anyOnGround) {
|
||||
braking = holdingButton;
|
||||
}
|
||||
}
|
||||
|
||||
public override void inputSetTurnOnState ()
|
||||
{
|
||||
if (driving && !usingGravityControl) {
|
||||
if (mainVehicleHUDManager.canSetTurnOnState) {
|
||||
setEngineOnOrOffState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetClimbState (bool state)
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn) {
|
||||
if (!useClimbEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSwimmingActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDesiresClimbingState (state);
|
||||
|
||||
if (state) {
|
||||
if (usingBoost) {
|
||||
mainVehicleCameraController.usingBoost (false, vehicleControllerSettings.boostCameraShakeStateName,
|
||||
vehicleControllerSettings.useBoostCameraShake, vehicleControllerSettings.moveCameraAwayOnBoost);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputToggleClimbState ()
|
||||
{
|
||||
if (driving && !usingGravityControl && isTurnedOn) {
|
||||
inputSetClimbState (!desiresClimbing);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class otherVehicleParts
|
||||
{
|
||||
public Transform COM;
|
||||
public GameObject chassis;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehicleSettings
|
||||
{
|
||||
public LayerMask layer;
|
||||
public GameObject vehicleCamera;
|
||||
public float brakeForce = 5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0dd4268f3ede8544a8f6c86250642b7
|
||||
timeCreated: 1473345364
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/sphereController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class turretController : vehicleController
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public otherVehicleParts vehicleParts;
|
||||
public vehicleSettings settings;
|
||||
|
||||
float lookAngle;
|
||||
|
||||
|
||||
public override void Awake ()
|
||||
{
|
||||
base.Awake ();
|
||||
|
||||
}
|
||||
|
||||
public override void vehicleUpdate ()
|
||||
{
|
||||
if (driving && settings.turretCanRotate) {
|
||||
horizontalAxis = mainInputActionManager.getPlayerMovementAxis ().x;
|
||||
|
||||
if (!useHorizontalInputLerp && !touchPlatform) {
|
||||
rawAxisValues = mainInputActionManager.getPlayerRawMovementAxis ();
|
||||
horizontalAxis = rawAxisValues.x;
|
||||
}
|
||||
|
||||
if (mainVehicleCameraController.currentState.useCameraSteer && horizontalAxis == 0) {
|
||||
localLook = vehicleParts.chassis.transform.InverseTransformDirection (mainVehicleCameraController.getLookDirection ());
|
||||
|
||||
if (localLook.z < 0f) {
|
||||
localLook.x = Mathf.Sign (localLook.x);
|
||||
}
|
||||
|
||||
steering = localLook.x;
|
||||
steering = Mathf.Clamp (steering, -1f, 1f);
|
||||
|
||||
horizontalAxis = steering;
|
||||
}
|
||||
|
||||
lookAngle -= horizontalAxis * settings.rotationSpeed;
|
||||
|
||||
if (settings.rotationLimited) {
|
||||
lookAngle = Mathf.Clamp (lookAngle, -settings.clampTiltXTurret.x, settings.clampTiltXTurret.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (driving && settings.turretCanRotate) {
|
||||
Quaternion targetRotation = Quaternion.Euler (0, -lookAngle, 0);
|
||||
|
||||
vehicleParts.chassis.transform.localRotation =
|
||||
Quaternion.Slerp (vehicleParts.chassis.transform.localRotation, targetRotation, Time.deltaTime * settings.smoothRotationSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
//the player is getting on or off from the vehicle, so
|
||||
public override void changeVehicleState ()
|
||||
{
|
||||
driving = !driving;
|
||||
|
||||
if (!driving) {
|
||||
StartCoroutine (resetTurretRotation ());
|
||||
|
||||
lookAngle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//the vehicle has been destroyed, so disabled every component in it
|
||||
public override void disableVehicle ()
|
||||
{
|
||||
//disable the controller
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
//reset the weapon rotation when the player gets off
|
||||
IEnumerator resetTurretRotation ()
|
||||
{
|
||||
Quaternion currentBaseYRotation = vehicleParts.chassis.transform.localRotation;
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
vehicleParts.chassis.transform.localRotation = Quaternion.Slerp (currentBaseYRotation, Quaternion.identity, t);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class otherVehicleParts
|
||||
{
|
||||
public GameObject chassis;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehicleSettings
|
||||
{
|
||||
public bool turretCanRotate;
|
||||
public bool rotationLimited;
|
||||
public float rotationSpeed;
|
||||
public float smoothRotationSpeed = 5;
|
||||
public Vector2 clampTiltXTurret;
|
||||
public GameObject vehicleCamera;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8498eeb64283e5842a5919aee0e6b02e
|
||||
timeCreated: 1474133772
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/turretController.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3dabe875e5952a49b96275213338562
|
||||
timeCreated: 1563666970
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Vehicles/Vehicle Controllers/vehicleController.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user