- Home /
turn player model into rag doll
Hi all,
I am making a 2.5d infinite runner game using a 3d model as the player. The 3d model is animated to run. I would like to turn the player model into a rag doll when the game is over. Here are a few code snippets before I elaborate on my problem...
The following code checks for user input, checks to see if the player is touching a platform then jumps if both of these conditions are met.
the second part checks to see if the player is touching the platform and if this condition is met applies acceleration.
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ //Android touch controls.
if(touchingPlatform){
numberOfJumps +=1f;
GUIManager.SetnumberOfJumps(numberOfJumps);
rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
audio.Play();
touchingPlatform = false;
}
}
if(transform.localPosition.y < gameOverY){
GameEventManager.TriggerGameOver();
}
speed = rigidbody.velocity.x;
//add some speed
if(touchingPlatform){
rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration);
}
here is part of my game over function which is relevant to my problem.
Public void GameOver () {
Renderer[] rs = GetComponentsInChildren<Renderer>();
foreach (Renderer r in rs)
r.enabled = false;
rigidbody.isKinematic = true;
}
The above code grabs each child of the model and turns off the renderer. it also makes the rigid body kinematic. As stated above, I need to turn him into a rag doll at game over.
My first idea was to have the player model as a rag doll to begin with and turn off his animation during the game over event. When I tried this the player model jumps and twitches while the game is running and doesn't accelerate.
Is this due to the way I am applying force to the rigid body? As I see it, a rag doll is a bunch of rigid bodies all together. Would I need to apply acceleration to each one or am I barking up the wrong tree?
Would a better (but more complicated) idea be store my players rotation, speed and position then hide it and instantiate a rag doll?
I've been trying to solve this for a while and I would appreciate any help.
Many thanks,
Paul.
I'd say go ahead and try and create a ragdoll and instantiate it in the position and rotation of the player. Here is what I have used. Anim Object being the player I had before and DeadReplacement the Ragdoll. You just have to create the ragdoll.
if (Health <= 0.0) { Destroy(gameObject); Instantiate( DeadReplacement, AnimObject.transform.position, AnimObject.transform.rotation);
}
You could set up your character with all the joints and rigidbodies beforehand. Once the game ends, iterate through all the rigidbodies and enable them
$$anonymous$$any thanks both of you. I won't have time to try either of these till the new year but I'll come back and let you know how it went.
Your answer
Follow this Question
Related Questions
Where could I get a Free 3d Ragdoll Model? 1 Answer
Ragdoll script vs Extra ragdoll model 0 Answers
Unity Robot - left forearm glitchy transform 0 Answers
Blender or Unity for animation? 4 Answers
Ragdoll effect on models 1 Answer