• 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 Massonator · Jan 24, 2016 at 04:08 PM · transformanimatorfightingpositon

Setting Transform.position inaccurate?

Hi guys,

I am working on a game with judo/ wrestling style grapples and throws. I've got two characters, each character has an animator, when one character hits the grapple button, I use the transform to place the receiver to be in the correct position. However, this method doesn't give the same results every time it's called. Sometimes the rotation will be wrong, sometimes the positioning. It's always kind of right, but never seems to be exactly where it should be, and the positioning never seems to be consistent.

Here's a snippet of my code.

 Vector3 playerPos = attackerAnim.transform.position;
         Vector3 playerDirection = attackerAnim.transform.forward;
         Quaternion playerRotation = attackerAnim.transform.rotation;
 
 if (attackerBattlestats.stamina > Moves.frontLight[movename][2]) {
                      
                     float oppDistance = 0.5f;
     
                     Vector3 oppPos = playerPos + playerDirection * oppDistance;
                     oppAnim.transform.position = oppPos;
     
                     opponent.transform.LookAt(attacker.transform.position);
                     attacker.transform.LookAt(opponent.transform.position);
     
                     attackerAnim.SetInteger("LightGrappleAttackAnim", Moves.frontLight[movename][4]);
                     oppAnim.SetInteger("LightGrappleReactAnim", Moves.frontLight[movename][4]);
     
                     IEnumerator playMoveAtt = moveset.stopAnim("LightGrappleAttackAnim", attackerAnim);
                     StartCoroutine(playMoveAtt);
     
                     IEnumerator playMoveRec = moveset.stopAnim("LightGrappleReactAnim", oppAnim);
                     StartCoroutine(playMoveRec);
 
                 }

This is part of a bigger method, animators (oppAnim and attackerAnim) are passed in, The animator.SetIntegermoves the animator from anystate to the selected grapple. The StopAnim IEnumerator changes the set integer back to 0, after the animation has started playing. The various BattleStates variables are just objects to hold characters health etc, also passed into the method.

I have a feeling it's because mecanim or something adds in some velocity/ momentum that changing the transform won't stop, but my google searches haven't confirmed this. There are no colliders, so I don't see why it isn't working.

Any help is much appreciated.

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 Teravisor · Jan 25, 2016 at 12:33 AM 1
Share

I can guess your grapple hook is child of something that is on character that's being animated? If so most likely it's $$anonymous$$ecanim changing transform constantly as it plays animation. Fixing is either unparenting it(might break something though) or setting transform after mecanim pass each frame (for example, LateUpdate()). I don't see where this method gets called: is it Update() or LateUpdate()? If it's Update() try moving it into LateUpdate(). If it's not called every frame, that's bad then as mecanim changes state each frame and you will need to update transform each frame.

avatar image Massonator · Jan 26, 2016 at 08:51 AM 0
Share

Thanks @Teravisor. It was called in Update() (sorry for not saying!), I have tried moving it to LateUpdate(), and that has helped make it a lot more consistent, but it's still not perfect. It's not actually a grapple hook, rather two human characters going through a judo throw like animation, ie two people grappling each other. They are both child objects of their own spawn object, but the spawn object doesn't move.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Play animation as the value changes from 0 to 1 with changing GameObject's position in unity 0 Answers

How can I apply vertical Root Motion on an object with a dynamic Rigidbody2D? 0 Answers

Why Editor throws Null Reference Exception when changing a transforms position while animation clips rec mode? 0 Answers

How do I move an object also moved by animator? 0 Answers

Root motion in child not moving with parent 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