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 JuanseCoello · Apr 11, 2014 at 11:33 PM · rigidbodycharacterragdollkinematic

How to make a ragdoll not rotate but still be non kinematic?

I have made a video describing the problems.

https://www.youtube.com/watch?v=xxWD_9d0Jnc&feature=youtu.be link text

I want to make a character system, composed by a ragdoll that can move, but doesnt act as a ragdoll, only the collisions od the bones, I prefer it to be non kinematic.

Is there some way to stop the rotation of the ragdoll, but still allow the movement? There is also another problem. In my script there is some lines that say:

   ragdoll = transform.FindChild("Armature") as Transform;
   rb = ragdoll.GetComponentInChildren(typeof(Rigidbody)) as Rigidbody;
   TP_Controller.rb.velocity = MoveVector;

This lines mean that all of the rigidbodies childs move with a movevector velocity. The problem is that all the bone colliders move at the same time. I would like to create a single bone (like the middle spine), to move and the rest of the armature ragdoll follows the movement, because if I cancel the rotation of every rigidbody of the ragdoll, each bone moves at its own direction, they dont act as a whole.

Any ideas? I will take any idea in consideration, ideas are very important for me, since I dont know what to do. So I will get this answer by myself since the unity community people dont help very much this days.

Here are the scripts:

Dont pay attention that they are too long, they only move the character sideways and vertically, and also applies gravity and slide, they move with a movevector Vector3 applied in worldspace.

To test this script you must have a ragdoll with the armature named Armature.

TP MOTOR

using UnityEngine; using System.Collections;

public class TP_Motor : MonoBehaviour {

 public static TP_Motor Instance;

 public float MoveSpeed = 20f;

 public float Gravity = 10f;


 public float TerminalVelocity = 20f;

 public Vector3 MoveVector { get; set; }
 public float VerticalVelocity { get; set; }

 void Awake()  // Debe quedarse en awake
 {
     Instance = this;
 }
 

 public void UpdateMotor()  // Debe quedarse en update motor
 {
     ProcessMotion();
 }

 void ProcessMotion()
 {
     // Transform MoveVector to World Space
     MoveVector = transform.TransformDirection(MoveVector);

     // Normalize MoveVector if Magnitude > 1
     if (MoveVector.magnitude > 1)
         MoveVector = Vector3.Normalize(MoveVector);

     // Multiply MoveVector by MoveSpeed
     MoveVector *= MoveSpeed;

     // Reapply VerticalVelocity MoveVector.y
     if (!TP_Controller.Instance.isgrounded == true)
     MoveVector = new Vector3(MoveVector.x, VerticalVelocity, MoveVector.z);

     // Apply Gravity 
     ApplyGravity();
         
     // Move Character in World Space
     TP_Controller.rb.velocity = MoveVector;



 }

 void ApplyGravity()
 {
     if (TP_Controller.Instance.isgrounded == true)
         return;

     if (MoveVector.y < -TerminalVelocity)
         MoveVector = new Vector3(MoveVector.x, MoveVector.y - Gravity * Time.deltaTime, MoveVector.z);
     if ((TP_Controller.Instance.isgrounded == false) && MoveVector.y > -1)
         MoveVector = new Vector3(MoveVector.x, -10, MoveVector.z);
 }

}

TP CONTROLLER

     using UnityEngine;
     using System.Collections;

     public class TP_Controller : MonoBehaviour 
       {
     public static TP_Controller Instance;
      public static Rigidbody rb;
      public static Transform ragdoll;


       RaycastHit hit;

      public bool isgrounded;

}

 public void Awake () // Debe quedarse en awake
 {

     ragdoll = transform.FindChild("Armature") as Transform;
     rb = ragdoll.GetComponentInChildren(typeof(Rigidbody)) as Rigidbody;

     Instance = this;

     animator = GetComponent<Animator>();

     rb.isKinematic = false;
       
 }
 

 void Update () 
 {
     if (Camera.mainCamera == null)
         return;

     GetLocomotionInput();

     TP_Motor.Instance.UpdateMotor();


     IsGrounded();

 }

 void IsGrounded()
 {

     RaycastHit hitInfo;
     if (Physics.Raycast(transform.position + Vector3.up * 0.8f, Vector3.down * 0.5f, out hitInfo, Mathf.Infinity))
      
     {
         if (hitInfo.distance > 0.1f) // Change .1f to what you need
             Debug.DrawRay(transform.position + Vector3.up * 0.05f, Vector3.down * 0.05f, Color.green);

             isgrounded = false;

         if (hitInfo.distance < 0.1f)
             isgrounded = true;
     }



 } 

 void GetLocomotionInput()
 {
     var deadZone = 0.1;

     TP_Motor.Instance.VerticalVelocity = TP_Motor.Instance.MoveVector.y;
     TP_Motor.Instance.MoveVector = Vector3.zero;

     if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
         TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));

     if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone)
         TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);
     
 }

}

Comment
Add comment · Show 2
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
avatar image JuanseCoello · Apr 11, 2014 at 11:45 PM 0
Share

$$anonymous$$aybe I havent explained well the problem, the problem is that the ragdoll crawls like a reptile, and I want it to move like the first part of the video, but as a ragdoll.

avatar image Radivarig · Apr 12, 2014 at 05:16 AM 0
Share

Check Character Joints and put some restrictions on them

0 Replies

· Add your reply
  • Sort: 

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision between rigid body zombie characters. 1 Answer

Making a falling ragdoll rigid before jump 0 Answers

How can I make character become a ragdoll with isKinematic? 1 Answer

Tracking Force Added to Kinematic Rigidbody 2 Answers

Should a Character Controller attach with Rigidbody? 2 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