Question by
icraftc4 · Sep 30, 2020 at 06:15 PM ·
animationanimator controllerragdollrespawnrespawning
Ragdoll death respawn help
I need help, I have an fps controller (its full body so same 3d person and 1st person animations) and have it set up to fall as a ragdoll when it dies, which works great it disables the animator then it waits 5 seconds, then respawns the player. The only problem is when it respawns sometimes the head is warped or the neck is warped and I literally have no idea what's wrong with it, heres my code, and a picture example of the bug.
public void die()
{
var gunPos = inv.weaponsHeld[inv.slot].transform.position;
GetComponent<Animator>().enabled = false;
setRigidbodyState(false);
setColliderState(true);
dead = true;
if (gameObject != null)
{
StartCoroutine(respawn(5f, gunPos));
}
}
IEnumerator respawn(float spawnDelay, Vector3 weaponPos)
{
inv.weaponsHeld[inv.slot].transform.position = weaponPos;
anim.SetBool("isCrouching", false);
anim.SetBool("isProning", false);
anim.SetBool("isReloading", false);
anim.SetBool("isAiming", false);
anim.SetBool("isRunning", false);
anim.SetBool("isWalking", false);
yield return new WaitForSeconds(spawnDelay);
dead = false;
setRigidbodyState(true);
setColliderState(false);
transform.position = new Vector3(Random.Range(15f, -15f), 5, Random.Range(15f, -15f));
GetComponent<Animator>().enabled = true;
}
void setRigidbodyState(bool state)
{
Rigidbody[] rigidbodies = GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody rigidbody in rigidbodies)
{
rigidbody.isKinematic = state;
}
GetComponent<Rigidbody>().isKinematic = !state;
}
void setColliderState(bool state)
{
Collider[] colliders = GetComponentsInChildren<Collider>();
foreach (Collider collider in colliders)
{
collider.enabled = state;
}
GetComponent<Collider>().enabled = !state;
}
exanoke.png
(352.3 kB)
Comment
Your answer
Follow this Question
Related Questions
I can't see or access a state in the Animation Controler 1 Answer
Applying permanent mask to player animators walk 0 Answers
Move player by animation or script? 3 Answers
Delay Animator Action in C#? 0 Answers