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 /
This question was closed Dec 18, 2016 at 06:48 PM by guenni for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by guenni · Dec 04, 2016 at 07:42 AM · mecanimgameobjects2d animation

[Unity v5.4] Aligned positioning not working when using Animations

Hi! I have a problem concerning Mecanim. I'm making a 2D game (probably not relevant to the problem) and within this game the user moves a GameObject aligned to a Grid. Everything works perfect, but it looks a bit stiff, because I position the GameObject by setting the desired location via (example code)

 transform.position += new Vector2(1, 0); // move right
 transform.position -= new Vector2(1, 0); // move left
 transform.position += new Vector2(0,1); // move up 
 // and so on

So I decided to make some animations (for moving to the left, right, up and down), that change the position of the GameObject (with Apply Root Motion, Root Motion Curves, Booleans and corresponding transitions) - again, works great in theory.

I wrote some code to handle the Animations that works as expected but: the GameObject isn't moved completely in the desired direction. For example:

     Animation MoveLeft:
     
     Keyframe 1 positions: X=0 and Y=0 
     Keyframe 2 positions: X=-1 and Y=0   

The GameObject moves in the desired direction but only 0.9 units, sometimes less.

I can't get it fixed but I guess, the animation isn't played until the end when Unity switches back to an "idle state", so that the GameObject doesn't reach the desired position (1 full unit). Or am I missing something? I'm nearly at the point to leave it that stiff because I can't get it to work as expected.

Every hint is more than welcome.

Best regards and thanks for reading.

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

  • Sort: 
avatar image
0

Answer by guenni · Dec 19, 2016 at 08:42 PM

I fixed the problem by adjusting the distance (it doesn't "jump" 1 unit in the desired direction but something like 0.9 unit) and fixing the position with a script that's called at the end of the animation.
The problem is: I modify the position and the size (image a leaping frog viewed from above - I recreated the illusion of motion by changing the size halfway of the animation).

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Performance question - Animations in spritesheet vs animation in Mecanim? 0 Answers

Instant transition with Mecanim (Unity 2d) 4 Answers

2D-How to call a synced layer animation up in script (Animator) 1 Answer

Why is this C# script causing lag spikes between the game objects being cycled?, 1 Answer

sync color change of objects c# 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