Skip to content

Commit

Permalink
wip respawning
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Jul 12, 2024
1 parent e158d98 commit c630a17
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 15 deletions.
30 changes: 26 additions & 4 deletions Assets/Scripts/Control&Input/OrbitCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public Camera Camera
private int targetIndex = 0;
private PlayerManager player;

private Coroutine trackingRoutine;

private void Start()
{
player = GetComponent<PlayerManager>();
Expand All @@ -62,17 +64,27 @@ public void Activate()
if (!MatchController.Singleton.IsRoundInProgress)
return;
otherPlayers = MatchController.Singleton.Players.Where(p => p != GetComponent<PlayerManager>()).ToArray();
StartCoroutine(WaitAndStopTrackingRagdoll());
trackingRoutine = StartCoroutine(WaitAndStopTrackingRagdoll());
}

public void Deactivate()
{
StopTracking();
StopCoroutine(trackingRoutine);
}

private IEnumerator WaitAndStopTrackingRagdoll()
{
yield return new WaitForSeconds(3f);
player.HUDController.DisplaySpectateHint();
InputManager.onSelect += SwitchTarget;
InputManager.onFirePerformed += SwitchTarget;
// TODO remove
InputManager.onZoomPerformed += Respawn;

yield return new WaitForSeconds(3f);
player.HUDController.DisplaySpectateHint();

yield return new WaitForSeconds(3f);
var isStillOnPlayer = target == player.AiAimSpot;
var isStillOnPlayer = isTracking && target == player.AiAimSpot;
if (isStillOnPlayer)
{
StopTracking();
Expand All @@ -81,6 +93,12 @@ private IEnumerator WaitAndStopTrackingRagdoll()
}
}

// TODO remove
private void Respawn(InputAction.CallbackContext ctx)
{
player.Respawn(FindObjectOfType<PlayerFactory>().GetRandomSpawnpoints().First());
}

private void SwitchTarget(InputAction.CallbackContext ctx)
{
if (!MatchController.Singleton.IsRoundInProgress)
Expand Down Expand Up @@ -110,6 +128,10 @@ private void StopTracking()
{
if (!camera)
return;
InputManager.onSelect -= SwitchTarget;
InputManager.onFirePerformed -= SwitchTarget;
// TODO remove
InputManager.onZoomPerformed -= Respawn;
isTracking = false;
camera.enabled = false;
ResetCamera();
Expand Down
39 changes: 39 additions & 0 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,45 @@ protected void TurnIntoRagdoll(DamageInfo info)
ragdollController.EnableRagdoll(force);
}

public virtual void Respawn(Transform spawnpoint)
{
Debug.Log("RESPAWNING????");

isAlive = true;
aimAssistCollider.SetActive(true);
aiTargetCollider.gameObject.SetActive(true);
if (playerShadow)
playerShadow.gameObject.SetActive(true);

// Disable components
GetComponent<PlayerMovement>().enabled = true;
// TODO give back health
healthController.enabled = true;
playerIK.enabled = true;
if (gunController)
gunController.gameObject.SetActive(true);
GunHolder.gameObject.SetActive(true);

if (inputManager)
{
var orbitCamera = GetComponent<OrbitCamera>();
orbitCamera.Deactivate();
}

// TODO: Make accurate hitbox forces for the different limbs of the player
var ragdollController = GetComponent<RagdollController>();
ragdollController.DisableRagdoll();


// post orbit and ragdoll reset
inputManager.PlayerCamera.enabled = true;

transform.position = spawnpoint.position;
transform.rotation = spawnpoint.rotation;
GetComponent<Rigidbody>().position = spawnpoint.position;
GetComponent<PlayerMovement>().SetInitialRotation(spawnpoint.rotation.eulerAngles.y);
}

/// <summary>
/// Function for setting a playerInput, adding movement related listeners to it
/// and performing other necessary operations that require playerInput/-Identity.
Expand Down
35 changes: 24 additions & 11 deletions Assets/Scripts/RagdollController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,42 @@ public class RagdollController : MonoBehaviour

public void EnableRagdoll(Vector3 knockbackForce)
{
animatorToDisable.enabled = false;
ToggleRagdoll(true);

rigidbodyToPush.AddForce(knockbackForce, ForceMode.Impulse);
}

public void DisableRagdoll()
{
ToggleRagdoll(false);
}

public void ToggleRagdoll(bool shouldEnable = true)
{
animatorToDisable.enabled = !shouldEnable;

foreach (var collider in collidersToDisable)
{
collider.enabled = false;
collider.enabled = !shouldEnable;
}
foreach (var collider in collidersToEnable)
{
collider.enabled = true;
collider.isTrigger = false;
collider.enabled = shouldEnable;
collider.isTrigger = !shouldEnable;
}
foreach (var rigidbody in rigidbodiesToDisable)
{
rigidbody.isKinematic = true;
rigidbody.useGravity = false;
rigidbody.AddForce(-rigidbody.GetAccumulatedForce());
rigidbody.isKinematic = shouldEnable;
rigidbody.useGravity = !shouldEnable;
if (shouldEnable)
rigidbody.AddForce(-rigidbody.GetAccumulatedForce());
}
foreach (var rigidbody in rigidbodiesToEnable)
{
rigidbody.isKinematic = false;
rigidbody.useGravity = true;
rigidbody.isKinematic = !shouldEnable;
rigidbody.useGravity = shouldEnable;
if (!shouldEnable)
rigidbody.AddForce(-rigidbody.GetAccumulatedForce());
}

rigidbodyToPush.AddForce(knockbackForce, ForceMode.Impulse);
}
}

0 comments on commit c630a17

Please sign in to comment.