Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MachCUBED · Dec 31, 2011 at 04:50 AM · movementcharactercontrollerragdoll

Ragdoll player character jumping unexpectedly when moved

Hi guys,

I made my player character into a ragdoll with the rag doll wizard, and the character also has a Character Controller component. When I try to test my game, the character can turn just fine using the keyboard or mouse. However, jumping (space) and moving forwards or backwards results in a strange behavior: the character's transform.y increases dramatically as long as a movement key is pressed, with the problem happening less noticeably when jumping. Once the player stops pressing the relevant key or moving their gamepad's left stick, the character floats downwards at a really slow, barely-notcable rate. This only started when I added a ragdoll component to my character, and here is my player movement script:

var speed = 3.0; var rotateSpeed = 3.0; var jumpSpeed: float = 1.0; var gravity: float = 10.0; // gravity acceleration

private var vSpeed: float = 0; // store vertical speed in a separate variable private var controller : CharacterController; private var locked = false; private var attacker : GameObject;

function Update () { controller = GetComponent(CharacterController);

// Rotate around y - axis transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

if (!locked) { // Move forward / backward // Move forward / backward var curSpeed = speed Input.GetAxis ("Vertical"); var moveDir = transform.forward curSpeed;

 // Jump code
 if (controller.isGrounded)
 {
  // if character is grounded...
     vSpeed = 0; // its vert speed is zero
     if (Input.GetButtonDown("Jump"))
     { // but if jump pressed, set it to jumpSpeed
         vSpeed = jumpSpeed;
     }
 }
 // apply gravity acceleration
 vSpeed -= gravity * Time.deltaTime;
 moveDir.y = vSpeed; // include vSpeed in  moveDir
 // moveDir * Time.deltaTime is the displacement since last frame
 controller.Move(moveDir * Time.deltaTime);

}

else { controller.Transform = attacker.transform; }

// Animate character if (Input.GetAxis("Vertical") > 0.1 || Input.GetAxis("Horizontal") > 0.1 || Input.GetAxis("Vertical") < -0.1 || Input.GetAxis("Horizontal") < -0.1) animation.CrossFade("run"); else { animation.CrossFade("idle"); } }

function LockedInJaws (stuckPos : Vector3, sender : GameObject) { locked = true; // animation.CrossFade("buttstomp", 0.2); / var playerController : ThirdPersonController = GetComponent(ThirdPersonController); while(!playerController.IsGrounded()) { yield;
}
/ transform.Translate(stuckPos, Space.Self); attacker = sender;

 Debug.Log("Player slammed, make the player move with the dog's head");
 // animation.Blend("buttstomp", 0, 0);

}

@script RequireComponent(CharacterController)

Why would my ragdoll component cause such behavior?

MachCUBED

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kesh · Jan 20, 2014 at 11:01 PM

This is caused by the rigidbodies in your ragdoll limbs colliding with your characterController collider or capsule collider. Toggling isKinematic to false on ragdoll limbs isn't enough to fix this. You need to also toggle detectCollisions on each ragdoll rigidboy as well. I use something like this to adjust each ragdoll rigidbody:

 public Rigidbody playerRigidbody;
 
 void setKinematic(bool newValue)
 {
     
             //Get an array of components that are of type Rigidbody
             Component[] components=GetComponentsInChildren(typeof(Rigidbody));
     
             //For each of the components in the array, treat the component as a Rigidbody and set its isKinematic and detectCollisions property
             foreach (Component c in components)
             {
                 (c as Rigidbody).isKinematic=newValue;
                 (c as Rigidbody).detectCollisions=!newValue;
             }
     
             //Sets PLAYER rigid body as opposite
             playerRigidbody.isKinematic = !newValue;
             playerRigidbody.detectCollisions = newValue;
     
 }


playerRigidbody is a public Transform of my player.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Character moving up/down & left/right while constantly going forward in Z 2 Answers

Why am I losing some inputs on Update function? 0 Answers

How do I fix my player jumping code? 2 Answers

Character keeps moving in one direction on its own 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges