Skip to content

Commit

Permalink
targeting doesn't switch to next target if current target is closer(i…
Browse files Browse the repository at this point in the history
…n angle) but not targetable, left trigger throttle for DT users, AGM cam smoothing, missiles in update instead of fixedupdate
  • Loading branch information
Sacchan-VRC committed Jan 2, 2021
1 parent bd3961b commit 3b196a7
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Guide_RU.mat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 52e355960b4a0d242b120fd53f7fe426, type: 3}
m_Texture: {fileID: 2800000, guid: 4d189d8105a3ac443b699086ea5e0286, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
Expand Down
32 changes: 32 additions & 0 deletions Other/MultiObjectToggle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class MultiObjectToggle : UdonSharpBehaviour
{
private int current = 0;
public GameObject[] ToggleObjs;
private void Interact()//entering the plane
{
current++;
if (current == ToggleObjs.Length)
{
current = 0;
}
int o = 0;
foreach (GameObject obj in ToggleObjs)
{
if (o != current)
{
obj.SetActive(false);
}
else
{
obj.SetActive(true);
}
o++;
}
}
}
6 changes: 1 addition & 5 deletions SF-1/Scripts/AAMController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void Start()
}
void LateUpdate()
{
float DeltaTime = Time.deltaTime;
//Debug.Log(gameObject.GetComponent<Rigidbody>().velocity.magnitude);
if (!ColliderActive)
{
Expand All @@ -81,11 +82,7 @@ void LateUpdate()
}
else Explode();//explode and give Lifetime another 10 seconds
}
}

private void FixedUpdate()
{
float DeltaTime = Time.deltaTime;
Vector3 Position = transform.position;
Vector3 TargetPos = Target.position;
float TargetDistance = Vector3.Distance(Position, TargetPos);
Expand Down Expand Up @@ -119,7 +116,6 @@ private void FixedUpdate()
TargDistlastframe = TargetDistance;
Lifetime += DeltaTime;
}

private void OnCollisionEnter(Collision other)
{
if (!Exploding)
Expand Down
72 changes: 46 additions & 26 deletions SF-1/Scripts/EngineController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public class EngineController : UdonSharpBehaviour
private float FullAGMsDivider;
private float FullBombsDivider;
private bool CanopyOpenCheck = true;
private Quaternion AGMCamLastFrame;
//float MouseX;
//float MouseY;
//float mouseysens = 1; //mouse input can't be used because it's used to look around even when in a seat
Expand Down Expand Up @@ -434,9 +435,6 @@ private void Start()
ReversingYawStrengthZero = YawThrustVecMulti == 0 ? -ReversingYawStrengthMulti : 1;
ReversingRollStrengthZero = RollThrustVecMulti == 0 ? -ReversingRollStrengthMulti : 1;

if (AAMTargets[AAMTarget] != null && AAMTargets[AAMTarget].transform.parent != null)
AAMCurrentTargetEngineControl = AAMTargets[AAMTarget].transform.parent.GetComponent<EngineController>();

FullAAMsDivider = 1f / NumAAM;
FullAGMsDivider = 1f / NumAGM;
FullBombsDivider = 1f / NumBomb;
Expand Down Expand Up @@ -1244,30 +1242,33 @@ private void LateUpdate()
//AGM Camera, more in hudcontroller
if (!AGMLocked)
{
Quaternion temp = Quaternion.identity;
Quaternion newangle;
if (InVR)
{
temp = localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation * Quaternion.Euler(0, 60, 0);
newangle = localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).rotation * Quaternion.Euler(0, 60, 0);
}
else if (!InEditor)//desktop mode
{
temp = localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).rotation;
newangle = localPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).rotation;
}
else//editor
{
temp = VehicleMainObj.transform.rotation;
newangle = VehicleMainObj.transform.rotation;
}
AGMCamRotSlerper = Quaternion.Slerp(AGMCamRotSlerper, temp, 70f * DeltaTime);
float ZoomLevel = AtGCam.fieldOfView / 90;
AGMCamRotSlerper = Quaternion.Slerp(AGMCamRotSlerper, newangle, ZoomLevel * 70f * DeltaTime);

if (AtGCam != null)
{
AGMRotDif = Vector3.Angle(AtGCam.transform.rotation * Vector3.forward, AGMCamRotSlerper * Vector3.forward);
AGMRotDif = Vector3.Angle(AtGCam.transform.rotation * Vector3.forward, AGMCamLastFrame * Vector3.forward);
// AGMRotDif = Vector3.Angle(AtGCam.transform.rotation * Vector3.forward, AGMCamRotSlerper * Vector3.forward);
AtGCam.transform.rotation = AGMCamRotSlerper;
//dunno if there's a better way to do this

Vector3 temp2 = AtGCam.transform.localRotation.eulerAngles;
temp2.z = 0;
AtGCam.transform.localRotation = Quaternion.Euler(temp2);
}
AGMCamLastFrame = newangle;
}


Expand Down Expand Up @@ -1603,7 +1604,19 @@ private void LateUpdate()
}
else//if cruise control disabled, use inputs
{
ThrottleInput = PlayerThrottle;
if (!InVR)
{
if (LTrigger > .07f)
ThrottleInput = LTrigger;
else
{
ThrottleInput = PlayerThrottle;
}
}
else
{
ThrottleInput = PlayerThrottle;
}
}
Fuel = Mathf.Clamp(Fuel - ((FuelConsumption * Mathf.Max(ThrottleInput, 0.35f)) * DeltaTime), 0, FullFuel);
if (Fuel < 200) ThrottleInput = Mathf.Clamp(ThrottleInput * (Fuel / 200), 0, 1);
Expand Down Expand Up @@ -1666,6 +1679,7 @@ private void LateUpdate()
{
if (!InVR)
{
//allow stick flight with gamepads
VRPitchRollInput = LStick;
JoystickPosYaw.x = RStick.x;
//make stick input square
Expand Down Expand Up @@ -1754,14 +1768,6 @@ private void LateUpdate()
}
else VehicleRigidbody.velocity = Vector3.zero;
}
PilotingInt = 0;
roll = 0;
pitch = 0;
yaw = 0;
RollInput = 0;
PitchInput = 0;
YawInput = 0;
ThrottleInput = 0;
/* PitchInput = Trim.x;
YawInput = Trim.y; */
}
Expand Down Expand Up @@ -2207,6 +2213,7 @@ private void AAMTargeting(float Lock_Angle)
Vector3 AAMNextTargetDirection = (TargetCheckerTransform.position - CenterOfMass.transform.position);
float NextTargetAngle = Vector3.Angle(VehicleMainObj.transform.forward, AAMNextTargetDirection);
float NextTargetDistance = Vector3.Distance(CenterOfMass.position, TargetCheckerTransform.position);
bool AAMCurrentTargetEngineControlNull = AAMCurrentTargetEngineControl == null ? true : false;

if (TargetChecker.activeInHierarchy)
{
Expand All @@ -2221,13 +2228,14 @@ private void AAMTargeting(float Lock_Angle)
{
RaycastHit hitnext;
//raycast to check if it's behind something
Physics.Raycast(HUDControl.transform.position, AAMNextTargetDirection, out hitnext, Mathf.Infinity, 133121 /* Default, Environment, and Walkthrough */, QueryTriggerInteraction.Ignore);
bool LineOfSightNext = Physics.Raycast(HUDControl.transform.position, AAMNextTargetDirection, out hitnext, Mathf.Infinity, 133121 /* Default, Environment, and Walkthrough */, QueryTriggerInteraction.Ignore);

if (hitnext.point != null
if ((LineOfSightNext
&& hitnext.collider.gameObject.layer == OutsidePlaneLayer
&& NextTargetAngle < Lock_Angle
&& NextTargetDistance < AAMMaxTargetDistance
&& NextTargetAngle < AAMCurrentTargetAngle)
|| (!AAMCurrentTargetEngineControlNull && AAMCurrentTargetEngineControl.Taxiing)) //prevent being unable to target next target if it's angle is higher than your current target and your current target happens to be taxiing and is therefore untargetable
{
//found new target
AAMCurrentTargetAngle = NextTargetAngle;
Expand All @@ -2236,6 +2244,7 @@ private void AAMTargeting(float Lock_Angle)
AAMCurrentTargetEngineControl = NextTargetEngineControl;
AAMLockTimer = 0;
AAMTargetedTimer = .6f;//give the synced variable time to update before sending targeted
AAMCurrentTargetEngineControlNull = AAMCurrentTargetEngineControl == null ? true : false;
if (HUDControl != null)
{
HUDControl.GUN_TargetSpeedLerper = 0f;
Expand All @@ -2254,24 +2263,24 @@ private void AAMTargeting(float Lock_Angle)
AAMTargetChecker = 0;

//if target is currently in front of plane, lock onto it
if (AAMCurrentTargetEngineControl == null)
if (AAMCurrentTargetEngineControlNull)
{ AAMCurrentTargetDirection = AAMCurrentTargetPosition - HUDControl.transform.position; }
else
{ AAMCurrentTargetDirection = AAMCurrentTargetEngineControl.CenterOfMass.position - HUDControl.transform.position; }
float AAMCurrentTargetDistance = AAMCurrentTargetDirection.magnitude;
//check if target is active, and if it's enginecontroller is null(dummy target), or if it's not null(plane) make sure it's not taxiing or dead.
//raycast to check if it's behind something
RaycastHit hitcurrent;
Physics.Raycast(HUDControl.transform.position, AAMCurrentTargetDirection, out hitcurrent, Mathf.Infinity, 133121 /* Default, Environment, and Walkthrough */, QueryTriggerInteraction.Ignore);
bool LineOfSightCur = Physics.Raycast(HUDControl.transform.position, AAMCurrentTargetDirection, out hitcurrent, Mathf.Infinity, 133121 /* Default, Environment, and Walkthrough */, QueryTriggerInteraction.Ignore);
//used to make lock remain for .25 seconds after target is obscured
if (hitcurrent.point == null || hitcurrent.collider.gameObject.layer != OutsidePlaneLayer)
if (LineOfSightCur == false || hitcurrent.collider.gameObject.layer != OutsidePlaneLayer)
{ AAMTargetObscuredDelay += DeltaTime; }
else
{ AAMTargetObscuredDelay = 0; }

if (!Taxiing
&& AAMTargets[AAMTarget].activeInHierarchy
&& (AAMCurrentTargetEngineControl == null || (!AAMCurrentTargetEngineControl.Taxiing && !AAMCurrentTargetEngineControl.dead)))
&& (AAMCurrentTargetEngineControlNull || (!AAMCurrentTargetEngineControl.Taxiing && !AAMCurrentTargetEngineControl.dead)))
{
if ((AAMTargetObscuredDelay < .25f)
&& AAMCurrentTargetAngle < Lock_Angle
Expand All @@ -2280,7 +2289,7 @@ private void AAMTargeting(float Lock_Angle)
AAMHasTarget = true;
if (NumAAM > 0) AAMLockTimer += DeltaTime;
//give enemy radar lock even if you're out of missiles
if (AAMCurrentTargetEngineControl != null && RStickSelection == 2)
if (!AAMCurrentTargetEngineControlNull && RStickSelection == 2)
{
//target is a plane
AAMTargetedTimer += DeltaTime;
Expand Down Expand Up @@ -2554,6 +2563,17 @@ public void ToggleLimits()
}
}
}
public void ZeroControlValues()
{
PilotingInt = 0;
roll = 0;
pitch = 0;
yaw = 0;
RollInput = 0;
PitchInput = 0;
YawInput = 0;
ThrottleInput = 0;
}
private void Assert(bool condition, string message)
{
if (!condition)
Expand Down
7 changes: 3 additions & 4 deletions SF-1/Scripts/HUDController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,22 +376,21 @@ private void LateUpdate()
{
AtGScreen.SetActive(true);
EngineControl.AtGCam.gameObject.SetActive(true);
float newzoom = 0;
//if turning camera fast, zoom out
if (EngineControl.AGMRotDif < .8f)
if (EngineControl.AGMRotDif < .13f)
{
RaycastHit camhit;
Physics.Raycast(EngineControl.AtGCam.transform.position, EngineControl.AtGCam.transform.forward, out camhit, Mathf.Infinity, 1);
if (camhit.point != null)
{
//dolly zoom //Mathf.Atan(100 <--the 100 is the height of the camera frustrum at the target distance
newzoom = Mathf.Clamp(2.0f * Mathf.Atan(100 * 0.5f / Vector3.Distance(gameObject.transform.position, camhit.point)) * Mathf.Rad2Deg, 1.5f, 90);
float newzoom = Mathf.Clamp(2.0f * Mathf.Atan(100 * 0.5f / Vector3.Distance(gameObject.transform.position, camhit.point)) * Mathf.Rad2Deg, 1.5f, 90);
EngineControl.AtGCam.fieldOfView = Mathf.Clamp(Mathf.Lerp(EngineControl.AtGCam.fieldOfView, newzoom, 1.5f * DeltaTime), 0.3f, 90);
}
}
else
{
newzoom = 80;
float newzoom = 80;
EngineControl.AtGCam.fieldOfView = Mathf.Clamp(Mathf.Lerp(EngineControl.AtGCam.fieldOfView, newzoom, 3.5f * DeltaTime), 0.3f, 90); //zooming in is a bit slower than zooming out
}
}
Expand Down
3 changes: 2 additions & 1 deletion SF-1/Scripts/PilotSeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public override void OnStationExited(VRCPlayerApi player)
EngineControl.localPlayer.SetVelocity(EngineControl.CurrentVel + EngineControl.VehicleMainObj.transform.up * 25);
EngineControl.Ejected = false;
}
else EngineControl.localPlayer.SetVelocity(EngineControl.CurrentVel);
else { EngineControl.localPlayer.SetVelocity(EngineControl.CurrentVel); }
EngineControl.EjectTimer = 2;
EngineControl.Hooked = false;
EngineControl.BrakeInput = 0;
Expand All @@ -165,6 +165,7 @@ public override void OnStationExited(VRCPlayerApi player)
EngineControl.EffectsControl.PlaneAnimator.SetInteger("missilesincoming", 0);
EngineControl.AAMLockTimer = 0;
EngineControl.AAMLocked = false;
EngineControl.ZeroControlValues();
if (EngineControl.CatapultStatus == 1) { EngineControl.CatapultStatus = 0; }//keep launching if launching, otherwise unlock from catapult

if (LeaveButton != null) { LeaveButton.SetActive(false); }
Expand Down
Binary file modified Textures/Guide_RU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 58 additions & 1 deletion Udon/EngineController.asset
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 281
Data: 282
- Name:
Entry: 7
Data:
Expand Down Expand Up @@ -16767,6 +16767,63 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: AGMCamLastFrame
- Name: $v
Entry: 7
Data: 962|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: fieldSymbol
Entry: 7
Data: 963|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor
- Name: internalType
Entry: 9
Data: 473
- Name: declarationType
Entry: 3
Data: 2
- Name: syncMode
Entry: 3
Data: 0
- Name: symbolResolvedTypeName
Entry: 1
Data: UnityEngineQuaternion
- Name: symbolOriginalName
Entry: 1
Data: AGMCamLastFrame
- Name: symbolUniqueName
Entry: 1
Data: AGMCamLastFrame
- Name: symbolDefaultValue
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: fieldAttributes
Entry: 7
Data: 964|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name: userBehaviourSource
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
Expand Down
Loading

0 comments on commit 3b196a7

Please sign in to comment.