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
2
Question by mastahuka · Jul 12, 2012 at 06:04 PM · collidersprite

How do you synchronize a sprite animation with a plane animation?

alt textHi,

For example lets say I have a character that is just a plane with a sprite for walking animation, now that character is holding a flash light and that flash light has to be a plane with a texture applied because I need to dim the light for game play purposes that's why I cant just paint it in my walk animation sprite.

What I need to do is pin that plane to follow the sprite animation of my character.

Maybe an image will make these clear, I was able to animate the collision plane in a 3d program, matching frame by frame the flash light to match the hand of my character. But in unity the plane animation with my sprite animation does not match in speed, my plane is a lot faster than the sprite sheet animation, I can lower the speed but it seams I'm just guessing and it never matches perfectly.

Thanks for your time.

synch_collision_sprite.jpg (73.9 kB)
Comment
Add comment · Show 4
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 Tim-Michels · Sep 11, 2012 at 10:45 AM 0
Share

$$anonymous$$y first guess, is that your sprite-animation is framerate-dependant. You should use Time to calculate your animation, not just a "number of frames". $$anonymous$$aybe you can post more details about how exactly you're doing the animation to help you further...

Greets

avatar image mastahuka · Sep 11, 2012 at 06:09 PM 0
Share

Here are some key Factors of how I'm doing the animation:

  1. I set the Project Fixed Timestep to 0.06

  2. The basic logic of the animation is this: I have a material with a png as texture. This png represents the spritesheet of the animation and I use the renderer.material.SetTextureOffset to move the offset over the material (based on a frame index) to animate it.

  3. I have a variable called FrameDelay that specifies the time to wait between changing from one frame to another. This helps me to run some animations faster than others.

  4. I have a variable called animDelay that specifies the time to wait before restarting the animation frame cycle. So the code looks more less like this.

void FixedUpdate () { //Controls time between animation cycles elapsedTime += Time.deltaTime; //Controls time between animation frames elapsedTimeFrame += Time.deltaTime; //if must start an animation cycle if (elapsedTime >= animDelay) { //If must change to the next frame if (elapsedTimeFrame >= FrameDelay || FrameDelay == 0f) {
//Calculate offset Vector3 offset = CalculateOffset(FrameIndex, TotalFrames); //$$anonymous$$ove the material offset renderer.material.SetTextureOffset("$$anonymous$$ainTex", offset); //Check if need to restart animation if (FrameIndex> TotalFrames) { //Restart Frame index FrameIndex = 0; //Restart the image offset
renderer.material.SetTextureOffset("
$$anonymous$$ainTex", StartingOffset); //Restart the Time elapsedTime = 0f; } //Restart time between frames elapsedTimeFrame = 0f; } } }

avatar image mastahuka · Sep 11, 2012 at 06:09 PM 0
Share

Sorry about the code, it does not gets the tabs :s

avatar image Tim-Michels · Sep 12, 2012 at 06:34 AM 0
Share

I've taken a look at your code, and I think I've found your problem. It's when you reset your elapsedTime and elapsedTimeFrame to 0. You should not just set it to 0, but subtract the correct value. The fact is that for instance your elapsedTime can be much bigger than animDelay, due to a small framedrop. In that case your ti$$anonymous$$g would be all messed up.

I would suggest, when you reset your ti$$anonymous$$g, you should do elapsedTime -= animDelay

I hope this makes any sense, but I would also like to add that it's kind of a weird idea to use Time.deltaTime in a FixedUpdate().

You should either use the Update() with Time.deltaTime or the FixedUpdate() with Time.fixedDeltaTime.

I really hope this helps you on your way.

Greets,

Tim

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Sprites don't match the position of the 2DColliders 0 Answers

problem with a box collider 2d. 0 Answers

Is it possible to detect which side of a sprite a touch came in from? 0 Answers

How to eliminate gaps between 2d colliders? 2 Answers

Personaje cambie de sprite al teleportarse [Characters change sprite to teleport] 0 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