Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 off99555 · Oct 03, 2018 at 09:37 AM · rotationrigidbodyjoints

How do I rotate finger joints using controller input?

Suppose I have an index finger composed of 3 cubes which all contain Rigidbody which have isKinematic set to true. In a hierarchy they are the parent and children like this cube1 -> cube2 -> cube3

I want to control how my finger curls using the controller which outputs strength in range 0-1, e.g. the ArrowUp button. Put simply, if I hold the up button, all the cubes would rotate around Z for 60 degrees. And if I release the button, it would rotate back to 0 degrees. (All degrees in between 0-60 are valid when the up strength is between 0-1)

How do I rotate the finger while also making it collide with other objects? For example, you could use the finger to kick a ball.

If I don't care about the collision, I can just use transform.Rotate(0, 0, buttonUpStrength) in the Update() function and attach this script to all the cubes. But I care about collision and rigidbody.MoveRotation() is not enough because the position of each child will stay at the same absolute position when I use it. So I need to use rigidbody.MovePosition() to move the children relative to the parent also. But it's still not enough, the animation is not smooth, I want the animation to be smooth so I'm thinking that AddTorque() might be a better way out, but I don't know how to use it as isKinematic=true objects cannot be used with AddTorque().

What is a smarter, simpler way of making the finger kick a ball, without the finger being pushed back by the ball?

This is how my finger looks like, it's just a cube. alt text This is my script, that I attach to all cubes, in the inspector, I set cube1's angle to be 60. The children will just copy the angle of the parent:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TestJointRotation : MonoBehaviour
 {
     public float angle;
     private Rigidbody rb, rbParent;
     private Vector3 originalPos;
     private Quaternion originalRot;
 
     void Start()
     {
         rb = GetComponent<Collider>().attachedRigidbody;
         if (transform.parent != null)
         {
             rbParent = transform.parent.GetComponent<Collider>().attachedRigidbody;
         }
 
         originalPos = transform.localPosition;
         originalRot = transform.localRotation;
     }
 
     void Update()
     {
         if (rbParent)
         {
             angle = rbParent.GetComponent<TestJointRotation>().angle;
         }
 
         var rotation = Quaternion.identity;
         if (rbParent) 
             rotation *= rbParent.rotation;
         rotation *= originalRot;
         rotation *= Quaternion.Euler(0, 0, Input.GetAxis("Vertical") * angle);
         rb.MoveRotation(rotation);
         if (rbParent)
             rb.MovePosition(transform.parent.TransformPoint(originalPos));
     }
 }
 

screenshot-2.png (132.1 kB)
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

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

148 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 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 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 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 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 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 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

Rotate object using off-center handle 0 Answers

How to restore a rigidbody rotation 1 Answer

Configurable Joints pass through colliders 2 Answers

How to rotate object about 2 axes (vertical y and depth z) using configurable joint. 0 Answers

How do I rotate the propellers on this drone? 1 Answer


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