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();
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.
↧