Skip to content

Commit

Permalink
added SC-1 and SB-1, update floatscript bike-turning functionality, a…
Browse files Browse the repository at this point in the history
…dded wave options to sea(noise)
  • Loading branch information
Sacchan-VRC committed Jul 1, 2021
1 parent 3d74135 commit 2dd9f96
Show file tree
Hide file tree
Showing 84 changed files with 18,123 additions and 1,490 deletions.
28 changes: 23 additions & 5 deletions AAGun/Scripts/AAGunSeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@

public class AAGunSeat : UdonSharpBehaviour
{
public AAGunController AAGunControl;
public GameObject HUDControl;
public GameObject SeatAdjuster;
[SerializeField] private AAGunController AAGunControl;
private HUDControllerAAGun HUDControl;
[SerializeField] private GameObject SeatAdjuster;
private Animator AAGunAnimator;
private VRCPlayerApi localPlayer;
private int ThisStationID;
private bool firsttime = true;
void Start()
{
Assert(AAGunControl != null, "Start: AAGunControl != null");
Assert(HUDControl != null, "Start: HUDControl != null");
Assert(SeatAdjuster != null, "Start: SeatAdjuster != null");

if (AAGunControl.VehicleMainObj != null) { AAGunAnimator = AAGunControl.VehicleMainObj.GetComponent<Animator>(); }
HUDControl = AAGunControl.HUDControl;

localPlayer = Networking.LocalPlayer;
}
Expand Down Expand Up @@ -49,10 +52,12 @@ private void Interact()
}
public override void OnStationEntered(VRCPlayerApi player)
{
if (firsttime) { InitializeSeat(); }//can't do this in start because hudcontrol might not have initialized
AAGunControl.EnterSetStatus();
}
public override void OnStationExited(VRCPlayerApi player)
{
if (firsttime) { InitializeSeat(); }
AAGunControl.LastHealthUpdate = Time.time;
if (player.isLocal)
{
Expand All @@ -63,14 +68,27 @@ public override void OnStationExited(VRCPlayerApi player)
AAGunControl.DoAAMTargeting = false;
AAGunAnimator.SetBool("inside", false);
if (SeatAdjuster != null) { SeatAdjuster.SetActive(false); }
//set X rotation 0 so people don't get the seat orientation bug when they enter again
AAGunControl.Rotator.transform.localRotation = Quaternion.Euler(new Vector3(0, AAGunControl.Rotator.transform.localRotation.eulerAngles.y, 0));
}
}
private void OnOwnershipTransferred()
{
AAGunControl.firing = false;
}
private void InitializeSeat()
{
HUDControl.FindSeats();
int x = 0;
foreach (VRCStation station in HUDControl.VehicleStations)
{
if (station.gameObject == gameObject)
{
ThisStationID = x;
HUDControl.PilotSeat = x;
}
x++;
}
firsttime = false;
}
private void Assert(bool condition, string message)
{
if (!condition)
Expand Down
24 changes: 24 additions & 0 deletions AAGun/Scripts/HUDControllerAAGun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,31 @@ private void Update()
//Elevation indicator
ElevationIndicator.rotation = Quaternion.Euler(newrot);
/////////////////


//Replacement for leavebuttons below this point
if (Input.GetKeyDown(KeyCode.Return) || Input.GetButtonDown("Oculus_CrossPlatform_Button4"))
{
ExitStation();
}
}
[System.NonSerializedAttribute] public int PilotSeat;
[System.NonSerializedAttribute] public int MySeat;
[System.NonSerializedAttribute] public int[] SeatedPlayers;
[System.NonSerializedAttribute] public VRCStation[] VehicleStations;
[System.NonSerializedAttribute] public int[] InsidePlayers;
public void ExitStation()
{
VehicleStations[MySeat].ExitStation(AAGunControl.localPlayer);
}
public void FindSeats()
{
VehicleStations = (VRC.SDK3.Components.VRCStation[])AAGunControl.VehicleMainObj.GetComponentsInChildren(typeof(VRC.SDK3.Components.VRCStation));
SeatedPlayers = new int[VehicleStations.Length];
foreach (int i in SeatedPlayers) SeatedPlayers[i] = -1;
}


private void Assert(bool condition, string message)
{
if (!condition)
Expand Down
94 changes: 80 additions & 14 deletions Other/FloatScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ public class FloatScript : UdonSharpBehaviour
[SerializeField] private float WaterForwardDrag = .1f;
[SerializeField] private float WaterRotDrag = .1f;
[SerializeField] private float WaterVelDrag = .1f;
[SerializeField] private float WaveHeight = .2f;
[SerializeField] private float WaveScale = 1;
[SerializeField] private float WaveSpeed = 1;

[Header("HoverBike Only")]
[SerializeField] private EngineController EngineControl;
[SerializeField] private bool HoverBikeTurning = false;
[SerializeField] private float HoverBikeTurningStrength = 1;
[SerializeField] private float BackThrustStrength = 5;
private float[] SuspensionCompression;
private float[] SuspensionCompressionLastFrame;
private float[] FloatPointHeightLastFrame;
private float[] DepthBeyondMaxSusp;
private float LastRayHitHeight = -99999999;
private Vector3[] FloatLocalPos;
private float LastRayHitHeight = float.MinValue;
private Vector3[] FloatPointForce;
private int currentfloatpoint;
private float depth;
float SuspDispToMeters;
private VRCPlayerApi localPlayer;
private bool InEditor = false;
private bool HitLandLast;
void Start()
{
localPlayer = Networking.LocalPlayer;
Expand All @@ -44,6 +55,16 @@ void Start()
FloatPointHeightLastFrame = new float[FloatPoints.Length];
DepthBeyondMaxSusp = new float[FloatPoints.Length];
FloatPointForce = new Vector3[FloatPoints.Length];
FloatLocalPos = new Vector3[FloatPoints.Length];
for (int i = 0; i != FloatPoints.Length; i++)
{
FloatLocalPos[i] = FloatPoints[i].localPosition;
}

}
private void OnEnable()
{
LastRayHitHeight = float.MinValue;
}
void FixedUpdate()
{
Expand All @@ -54,28 +75,36 @@ void FixedUpdate()
}
private void Floating()
{
//fire test ray to check if it's worth firing another ray, and to check the height of the water/ground surface and if it's water or land
if (LastRayHitHeight < transform.position.y)
{
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit, 5, 1, QueryTriggerInteraction.Collide))
//15 meters should be far enough for this to work with any size of plane, needs to be increase if you're trying to make something gigantic fly
if (Physics.Raycast(transform.position, -Vector3.up, out hit, 15, 1, QueryTriggerInteraction.Collide))
{
if (DoOnLand || hit.collider.isTrigger)
if (hit.collider.isTrigger)//trigger = water
{
LastRayHitHeight = hit.point.y;
HitLandLast = false;
}
else
{
HitLandLast = true;
}

if (DoOnLand || !HitLandLast)
{
LastRayHitHeight = hit.point.y;
}
}
else
{
LastRayHitHeight = float.MinValue;
}
}


//if the water/ground level found above is higher than the current floatpoint, values are based on how far underneath the water it is rather than using a raycast to it
if (LastRayHitHeight > FloatPoints[currentfloatpoint].position.y)
{
DepthBeyondMaxSusp[currentfloatpoint] = LastRayHitHeight - FloatPoints[currentfloatpoint].position.y;
//float is under da wata
SuspensionCompression[currentfloatpoint] = 1;
SuspensionCompressionLastFrame[currentfloatpoint] = 1;

Expand All @@ -87,10 +116,19 @@ private void Floating()
FloatPointForce[currentfloatpoint] = Vector3.up * (FloatForce + (CompressionDifference * SuspDispToMeters));
FloatPointHeightLastFrame[currentfloatpoint] = FloatPoints[currentfloatpoint].position.y;
}
else
else//check depth and calc values for one floatpoint per frame
{
DepthBeyondMaxSusp[currentfloatpoint] = 0;
//check depth of one floatpoint per frame
if (!HitLandLast)//move floats around to simulate waves
{
Vector3 floatpos = FloatPoints[currentfloatpoint].position;
float time = Time.time;
FloatPoints[currentfloatpoint].localPosition = new Vector3(FloatLocalPos[currentfloatpoint].x, FloatLocalPos[currentfloatpoint].y - (Mathf.PerlinNoise(((floatpos.x + (time * WaveSpeed)) * WaveScale), ((floatpos.z + (time * WaveSpeed)) * WaveScale)) * WaveHeight), FloatLocalPos[currentfloatpoint].z);
}
else//we're a hoverbike-like vehicle that is currently over land, no waves
{
FloatPoints[currentfloatpoint].localPosition = FloatLocalPos[currentfloatpoint];
}
RaycastHit hit;
if (Physics.Raycast(FloatPoints[currentfloatpoint].position, -Vector3.up, out hit, SuspMaxDist, 1, QueryTriggerInteraction.Collide))
{
Expand All @@ -113,10 +151,13 @@ private void Floating()
FloatPointForce[currentfloatpoint] = Vector3.zero;
}
}
//set float back to it's original position before adding forces
FloatPoints[currentfloatpoint].localPosition = FloatLocalPos[currentfloatpoint];

depth = 0;
for (int i = 0; i != SuspensionCompression.Length; i++)
{
depth += SuspensionCompression[i] + DepthBeyondMaxSusp[i];
depth += SuspensionCompression[i] + (DepthBeyondMaxSusp[i] * SuspDispToMeters);
}
if (depth > 0)
{//apply last calculated floating force to all floatpoints
Expand All @@ -129,11 +170,36 @@ private void Floating()
}

Vector3 Vel = VehicleRigidbody.velocity;
float sidespeed = Vector3.Dot(Vel, VehicleTransform.right);
float forwardspeed = Vector3.Dot(Vel, VehicleTransform.forward);
Vector3 right = VehicleTransform.right;
Vector3 forward = VehicleTransform.forward;
Vector3 up = VehicleTransform.up;

float sidespeed = Vector3.Dot(Vel, right);
float forwardspeed = Vector3.Dot(Vel, forward);

VehicleRigidbody.AddForceAtPosition(VehicleTransform.right * -sidespeed * WaterSidewaysDrag * depth, FloatPoints[currentfloatpoint].position, ForceMode.Force);
VehicleRigidbody.AddForceAtPosition(VehicleTransform.forward * -forwardspeed * WaterForwardDrag * depth, FloatPoints[currentfloatpoint].position, ForceMode.Force);
if (HoverBikeTurning)
{
float RightY = Mathf.Abs(right.y);
right.y = 0;
if (Vector3.Dot(Vel, -up) > 0)
{
right = right.normalized * (1 + (RightY * HoverBikeTurningStrength));
}
else
{
right = Vector3.zero;
}
float BackThrustAmount = -((Vector3.Dot(Vel, forward)) * BackThrustStrength);
Debug.Log(BackThrustAmount);
if (BackThrustAmount > 0)
{ VehicleRigidbody.AddForce(forward * BackThrustAmount * depth * EngineControl.ThrottleInput); }
VehicleRigidbody.AddForce(right * -sidespeed * WaterSidewaysDrag * depth, ForceMode.Force);
}
else
{
VehicleRigidbody.AddForceAtPosition(right * -sidespeed * WaterSidewaysDrag * depth, FloatPoints[currentfloatpoint].position, ForceMode.Force);
}
VehicleRigidbody.AddForceAtPosition(forward * -forwardspeed * WaterForwardDrag * depth, FloatPoints[currentfloatpoint].position, ForceMode.Force);

currentfloatpoint++;
if (currentfloatpoint == FloatPoints.Length) { currentfloatpoint = 0; }
Expand Down
8 changes: 8 additions & 0 deletions SB-1.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added SB-1/EngineIdle_SB1.wav
Binary file not shown.
22 changes: 22 additions & 0 deletions SB-1/EngineIdle_SB1.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added SB-1/SB-1.fbx
Binary file not shown.
Loading

0 comments on commit 2dd9f96

Please sign in to comment.