Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leantween canceling wrong ids, fix #422, fix first person arm culling on zoom and certain viewing angles #430

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Prefabs/Characters/PlayerArmLeft.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ SkinnedMeshRenderer:
m_RootBone: {fileID: 7971391927095658884}
m_AABB:
m_Center: {x: -0.010198317, y: -0.0017878572, z: 0.04950676}
m_Extent: {x: 0.0062388154, y: 0.009813513, z: 0.0126058515}
m_Extent: {x: 0.01333882, y: 0.01581351, z: 0.02560585}
m_DirtyAABB: 0
--- !u!1 &8321719110810010550
GameObject:
Expand Down
6 changes: 3 additions & 3 deletions Assets/Prefabs/Characters/PlayerArmRight.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Transform:
- {fileID: 5880885916632462744}
- {fileID: 3535131488769462984}
m_Father: {fileID: 0}
m_RootOrder: -1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7601771935898208010
MonoBehaviour:
Expand Down Expand Up @@ -631,8 +631,8 @@ SkinnedMeshRenderer:
m_BlendShapeWeights: []
m_RootBone: {fileID: 7158862323430776054}
m_AABB:
m_Center: {x: -0.010195851, y: 0.012608443, z: -0.0026928633}
m_Extent: {x: 0.006238593, y: 0.010776787, z: 0.0099769235}
m_Center: {x: -0.010195851, y: 0.01960844, z: -0.0026928633}
m_Extent: {x: 0.01538593, y: 0.01577679, z: 0.019976923}
m_DirtyAABB: 0
--- !u!1 &4721697430436054245
GameObject:
Expand Down
2 changes: 2 additions & 0 deletions Assets/Prefabs/Gamestate/StaticInfo.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ MonoBehaviour:
extensionAuction: {fileID: 11400000, guid: ad4a13bed7ceda243beb3334b23d48b0, type: 2}
startingBody: {fileID: 11400000, guid: bf9666eedd80829a0a6b59278813ba72, type: 2}
startingBarrel: {fileID: 11400000, guid: 89eab92daa1634e84ace980d00e1880e, type: 2}
startingExtension: {fileID: 0}
secretNames: {fileID: 11400000, guid: 2f3309b3d89e8224e9bac1c33fd04eed, type: 2}
cameraFov: 90
32 changes: 19 additions & 13 deletions Assets/Scripts/Augment/AugmentImplementations/DDRBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public class DDRBody : GunBody
[SerializeField]
private Precision[] precisionsGoodToBad;

LTDescr arrowMover;
int arrowMoverTween;
int screenFlasherTween;
int screenPulseAnimatorTween;
int textAnimatorTween;

private float secondsPerUnitHeight;
private float musicPace;
Expand Down Expand Up @@ -82,16 +85,16 @@ public override void Start()
? MusicTrackManager.Singleton.TrackOffset
: secondsPerArrow - (MusicTrackManager.Singleton.TimeSinceTrackStart % secondsPerArrow);

arrowMover = LeanTween.value(gameObject, SetArrowHeigth, startHeight, screenHeight, secondsPerUnitHeight * (screenHeight - startHeight))
arrowMoverTween = LeanTween.value(gameObject, SetArrowHeigth, startHeight, screenHeight, secondsPerUnitHeight * (screenHeight - startHeight))
.setDelay(delay)
.setRepeat(-1)
.setOnComplete(ResetArrow);
.setOnComplete(ResetArrow).id;

LeanTween.value(gameObject, SetBackgroundZoom, 0.5f, 1.5f, musicPace)
screenPulseAnimatorTween = LeanTween.value(gameObject, SetBackgroundZoom, 0.5f, 1.5f, musicPace)
.setDelay(delay)
.setLoopPingPong()
.setOnComplete(
() => animator.OnFire(gunController.stats));
() => animator.OnFire(gunController.stats)).id;

animator.OnInitialize(gunController.stats);

Expand All @@ -118,16 +121,18 @@ protected override void Reload(GunStats stats)

if (!precision.HasValue)
return;

if (LeanTween.isTweening(textAnimatorTween))
LeanTween.cancel(textAnimatorTween);
precisionText.enabled = true;
precisionText.text = precision.Value.text;
precisionText.color = precision.Value.color;
precisionText.gameObject.LeanScale(new Vector3(1.1f, 1.1f, 1.1f), 0.5f)
textAnimatorTween = LeanTween.scale(precisionText.gameObject, new Vector3(1.1f, 1.1f, 1.1f), 0.5f)
.setEasePunch()
.setOnComplete(
() => precisionText.enabled = false);

LeanTween.value(gameObject, SetFlashFactor, 0, 50f, 0.5f).setEasePunch();
() => precisionText.enabled = false).id;
if (LeanTween.isTweening(screenFlasherTween))
LeanTween.cancel(screenFlasherTween);
screenFlasherTween = LeanTween.value(gameObject, SetFlashFactor, 0, 50f, 0.5f).setEasePunch().id;

gunController.Reload(reloadEfficiencyPercentage * precision.Value.awardFactor);
animator.OnReload(gunController.stats);
Expand Down Expand Up @@ -169,11 +174,12 @@ private void ArrowSelect(InputAction.CallbackContext ctx)

private void ResetAndStartArrowTween()
{
LeanTween.cancel(arrowMover.id);
if (LeanTween.isTweening(arrowMoverTween))
LeanTween.cancel(arrowMoverTween);
ResetArrow();
arrowMover = LeanTween.value(gameObject, SetArrowHeigth, arrowHeight, screenHeight, secondsPerUnitHeight * (screenHeight - arrowHeight))
arrowMoverTween = LeanTween.value(gameObject, SetArrowHeigth, arrowHeight, screenHeight, secondsPerUnitHeight * (screenHeight - arrowHeight))
.setRepeat(-1)
.setOnComplete(ResetArrow);
.setOnComplete(ResetArrow).id;
}

private void SetArrowHeigth(float heigth)
Expand Down
9 changes: 5 additions & 4 deletions Assets/Scripts/Augment/GunController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void SetPlayer(PlayerManager player)

private bool isFiring = false;

private LTDescr recoilTween;
private int recoilTween;
private int zoomTween;

private void Start()
{
Expand Down Expand Up @@ -164,14 +165,14 @@ public void PlayRecoil()

public void PlayRecoil(GunStats stats)
{
if (recoilTween != null)
if (LeanTween.isTweening(recoilTween))
{
LeanTween.cancel(recoilTween.id);
LeanTween.cancel(recoilTween);
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, localGunZOffset);
}
var moveAmount = Player != null ? 0.3f : 0.6f;
// TODO reduce tween time based on fire rate
recoilTween = gameObject.LeanMoveLocalZ(moveAmount, 0.2f).setEasePunch();
recoilTween = gameObject.LeanMoveLocalZ(moveAmount, 0.2f).setEasePunch().id;
}

private void ShotFired()
Expand Down
27 changes: 20 additions & 7 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public class PlayerMovement : MonoBehaviour
public delegate void MovementEventBody(Rigidbody body);
public MovementEventBody onMove;

private int gunCrouchPerformedTween;
private int cameraCrouchPerformedTween;
private int gunCrouchCanceledTween;
private int cameraCrouchCanceledTween;

void Start()
{
body = GetComponent<Rigidbody>();
Expand All @@ -142,7 +147,7 @@ public void SetPlayerInput(InputManager player)
localGunHolderX = gunHolder.transform.localPosition.x;
localGunHolderHeight = gunHolder.transform.localPosition.y;
playerCamera = inputManager.GetComponent<Camera>();
startingFov = playerCamera.fieldOfView;
startingFov = StaticInfo.Singleton.CameraFov;
Fueredoriku marked this conversation as resolved.
Show resolved Hide resolved

if (MatchController.Singleton)
MatchController.Singleton.onRoundEnd += ResetZoom;
Expand Down Expand Up @@ -199,9 +204,17 @@ private void ResetZoom()

private void OnCrouch(InputAction.CallbackContext ctx)
{
if (LeanTween.isTweening(inputManager.gameObject))
if (LeanTween.isTweening(cameraCrouchCanceledTween))
{
LeanTween.cancel(cameraCrouchCanceledTween);
LeanTween.cancel(gunCrouchCanceledTween);
inputManager.transform.localPosition = new Vector3(inputManager.transform.localPosition.x, localCameraHeight, inputManager.transform.localPosition.z);
gunHolder.transform.localPosition = new Vector3(gunHolder.transform.localPosition.x, localGunHolderHeight, gunHolder.transform.localPosition.z);
}
if (LeanTween.isTweening(cameraCrouchPerformedTween))
{
LeanTween.cancel(inputManager.gameObject);
LeanTween.cancel(cameraCrouchPerformedTween);
LeanTween.cancel(gunCrouchPerformedTween);
inputManager.transform.localPosition = new Vector3(inputManager.transform.localPosition.x, localCameraHeight, inputManager.transform.localPosition.z);
gunHolder.transform.localPosition = new Vector3(gunHolder.transform.localPosition.x, localGunHolderHeight, gunHolder.transform.localPosition.z);
}
Expand All @@ -220,8 +233,8 @@ private void OnCrouch(InputAction.CallbackContext ctx)
{
animator.SetBool("Crouching", false);
strafeForce = strafeForceGrounded;
inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f);
gunHolder.LeanMoveLocalY(localGunHolderHeight, 0.2f);
cameraCrouchCanceledTween = inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f).id;
gunCrouchCanceledTween = gunHolder.LeanMoveLocalY(localGunHolderHeight, 0.2f).id;
isDashing = false;
onLanding -= StartCrouch;
}
Expand All @@ -232,8 +245,8 @@ private void StartCrouch()
{
animator.SetBool("Crouching", true);
strafeForce = strafeForceCrouched;
inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f);
gunHolder.LeanMoveLocalY(localGunHolderHeight - crouchedHeightGunOffset, 0.2f);
cameraCrouchPerformedTween = inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f).id;
gunCrouchCanceledTween = gunHolder.LeanMoveLocalY(localGunHolderHeight - crouchedHeightGunOffset, 0.2f).id;
}

private void EnableDash()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void SetLayerOnSubtree(GameObject node, int layer)

private void PlayOnHit()
{
if (Random.Range(0, 1000) > 5)
if (Random.Range(0, 10000) > 5)
Fueredoriku marked this conversation as resolved.
Show resolved Hide resolved
{
hitSounds.Play(audioSource);
}
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Gamestate/StaticInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public class StaticInfo : MonoBehaviour
public ReadOnlyArray<Item> Extensions;
public ReadOnlyArray<OverrideName> SecretNames;

[Header("Settings")]
[SerializeField]
private float cameraFov;
public float CameraFov => cameraFov;

void Start()
{
#region Singleton boilerplate
Expand Down
15 changes: 10 additions & 5 deletions Assets/Scripts/UI/PlayerHUDController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class PlayerHUDController : MonoBehaviour
private const float ammoSpinDegrees = 30;
private const float availableDegrees = 270;

private int ammoTween;


[Header("Death")]

Expand Down Expand Up @@ -73,6 +75,7 @@ public class PlayerHUDController : MonoBehaviour

[SerializeField]
private RectTransform scopeZoom;
private int scopeTween;


void Start()
Expand Down Expand Up @@ -127,16 +130,16 @@ public void OnDamageTaken(float damage, float currentHealth, float maxHealth)

public void UpdateOnFire(float ammoPercent)
{
if (LeanTween.isTweening(ammoHud.gameObject))
if (LeanTween.isTweening(ammoTween))
{
LeanTween.cancel(ammoHud.gameObject);
LeanTween.cancel(ammoTween);
ammoBar.gameObject.transform.eulerAngles = new Vector3(ammoBar.gameObject.transform.eulerAngles.x, ammoBar.gameObject.transform.eulerAngles.y, 0);
}

ammoCapacityMaterial.SetFloat("_Arc2", (1 - ammoPercent) * availableDegrees);
ammoHud.gameObject.LeanRotateAroundLocal(Vector3.forward, ammoSpinDegrees, 0.5f).setEaseSpring()
ammoTween = ammoHud.gameObject.LeanRotateAroundLocal(Vector3.forward, ammoSpinDegrees, 0.5f).setEaseSpring()
.setOnStart(
() => ammoBar.gameObject.transform.Rotate(new Vector3(0, 0, -ammoSpinDegrees)));
() => ammoBar.gameObject.transform.Rotate(new Vector3(0, 0, -ammoSpinDegrees))).id;
}

public void UpdateOnReload(float ammoPercent)
Expand All @@ -160,7 +163,9 @@ private void SetHealthBar(float width)

public void TweenScope(float alpha, float seconds)
{
scopeZoom.LeanAlpha(alpha, seconds).setEaseInOutCubic();
if (LeanTween.isTweening(scopeTween))
LeanTween.cancel(scopeTween);
scopeTween = scopeZoom.LeanAlpha(alpha, seconds).setEaseInOutCubic().id;
}

public void UpdateDamageBorder(float intensity)
Expand Down