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 jakejolli · May 20, 2016 at 04:04 PM · animation2dsprites

Evenly distributing sprites in an animation

Is there a way to evenly distribute sprites along the timeline in an animation?

I know that I can change the sample rate to speed up/slow down the sprite animation, but this won't work for my purposes. I need to be able to create an animation of a given length, drop my sprite in that animation and ensure that they're evenly distributed within that amount of time (in order to ensure synchronization with the animation of other gameobjects being animated from the same animator).

See this related question for more info.

Comment
Add comment · Show 3
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 FortisVenaliter · May 20, 2016 at 04:52 PM 0
Share

I'm not 100% sure what you are asking here, but I think the answer I gave in your linked question will solve both issues.

avatar image jakejolli FortisVenaliter · May 20, 2016 at 06:57 PM 0
Share

While your other post was definitely helpful, it doesn't really address this issue, unless syncing an animation layer would essentially achieve this?

avatar image FortisVenaliter jakejolli · May 20, 2016 at 07:01 PM 0
Share

I think so, but, like I said, I'm not really sure what you're asking.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by phxvyper · May 20, 2016 at 10:42 PM

If I understand what you're asking, this is simple division.

Say you have 100 sprites in an animation, n = 100; And you have an animation that is 2 seconds long, t = 2;

In order to even distribute n sprites along an animation of t length, you have to find the dt (change in t) in which you distribute this. In order to find that period of time per sprite, you would divide t by n:

 t / n = 2 (seconds) / 100 (sprites)
 2 / 100 = 0.02/1 (seconds/sprites) or dt = 0.02.

Start your first sprite at t = 0, then increment t by dt for each sprite in your animation and place that sprite at that time.

e.g. sprite 5 should be at t = dt * 4 = 0.08

EDIT:

You can do math in code. The following code is basically pseudo code since it doesn't use Unity's API whatsoever, but you can apply it to whatever system you're using probably.

Since animations use a frame system, you'd have to find out a framerate:

 rate = n / t = 100 / 2 = 50 fps;

and this can be applied in code:

 struct Animation {
     float rate;
     Sprite[] frames;
     public Animation(float rate, params Sprite[] frames) {
         this.rate = rate;
         this.frames = frames;
     }
 }
 
 Animation CreateAnimationFromSprites(Sprite[] sprites, float animationLength) {
     float rate = (sprites.Length / animationLength);
 
     return new Animation(rate, sprites);
 }

and all you'll have to supply is your collection of sprites, and the length of the animation.

Comment
Add comment · Show 3 · 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
avatar image jakejolli · May 20, 2016 at 11:01 PM 0
Share

Thanks. That's exactly what I want to do, but can it be automated?

avatar image phxvyper jakejolli · May 21, 2016 at 12:13 AM 0
Share

I added new information to explain automation in code, just call that CreateAnimationFromSprites function whenever you want to create an animation - but make sure you translate it to use whatever Animation system you're implementing!

avatar image jakejolli phxvyper · May 21, 2016 at 03:19 AM 0
Share

Awesome, thank you. I'll have to fiddle with this and let you know how it works

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

102 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

Related Questions

2d Animation sprites - right way? 0 Answers

2d sprite animation issue 2 Answers

Animating hair over sprite animation 0 Answers

Lighting an Animated Player 0 Answers

How to swap sprites? 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