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 gfixler · Sep 01, 2010 at 04:19 AM · freezerotationstopping-animation

stop animation on a single joint?

Is there a way to tell one joint in an animated character to stop? For example, a shoulder (elbow, wrist...) of an arm holding something should stop swinging with the run cycle and just stay out in front of the character. Thanks!

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
2

Answer by MaDDoX · Nov 30, 2010 at 08:30 PM

Your best bet there is simply overriding the animation (ie. in LateUpdate) with something to re-aim your arm to a desired target. I've done a half-baked script that allows me to do just that. Of course you'll have to set a way to toggle and untoggle the script for the animations where you don't want the arm re-aiming forward, you can for instance use triggers in animation clips - ctrl+D them if they're imported to make them editable in the animation window. I've tried the script provided in the FPS example (from the Unity3D site) but I found it too tied to their specific setup, so it wouldn't suit me.

Here goes my script, to set it up what I do is simply drag'ndrop an empty gameobject there and move it around interactively in the editor window (while the game's running) plus tweak the "twist" settings until I find the right resulting orientation for the joint (right forearm in my case). Then i write the coordinates down and set it again out of playtime. Kinda of a lame "designer code" solution I know, but it works heh :) If someone can code a more elegant way to do this, please return the favor - even if this was useful just as inspiration - and share k? Good luck!

 using UnityEngine;
 using System.Collections;
 public class AimFix : MonoBehaviour
 {
 
 public Transform target;
 public Transform joint;
 public bool smooth = true;
 public float effect = 1; //6
 public Vector3 twist = Vector3.zero;
 
 private Vector3 targetPos;
 private Quaternion _finalrotation; 
 
 void LateUpdate ()
 {    
     if (effect <= 0) return;
     if (target)
     {
         if (smooth)
         {   // Look at and dampen the rotation
             Vector3 lerpedRotation_e = Vector3.zero;
             Quaternion aimRotation_q;
 
             targetPos = target.position;
             targetPos.y = joint.position.y;
             targetPos.z = -targetPos.z;
             aimRotation_q = Quaternion.LookRotation(joint.position - targetPos);
 
             lerpedRotation_e.x = Mathf.Lerp(lerpedRotation_e.x, aimRotation_q.eulerAngles.x, effect * Time.deltaTime);
             lerpedRotation_e.y = Mathf.Lerp(lerpedRotation_e.y, aimRotation_q.eulerAngles.y, effect * Time.deltaTime); 
             lerpedRotation_e.z = Mathf.Lerp(lerpedRotation_e.z, aimRotation_q.eulerAngles.z, effect * Time.deltaTime);
 
 
             _finalrotation = Quaternion.Euler(lerpedRotation_e.x + twist.x, lerpedRotation_e.y + twist.y, lerpedRotation_e.z + twist.z);
             joint.rotation = _finalrotation;
         }
         else
         {   // Just lookat
             joint.LookAt(target);
         }
     }
 }
 }
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

No one has followed this question yet.

Related Questions

How do i keep a rigidbody upright? Looking for best way to freeze rotation 1 Answer

how to lock rotation 1 Answer

Sound and Animation script assistance needed. 1 Answer

I cannot freeze both position on one axis together with rotation 1 Answer

Animation stops when starting a new one 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