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
1
Question by justaleaf · Apr 15, 2014 at 03:31 AM · 2dphysicsspritegravity

How to get animated sprite to adhere to gravity?

I am making a gravity-basics puzzle game where the player rotates the world to navigate the hero (ball) through each level. Things were going pretty well until I tried to animate one of the baddies. Once I added an animation (created using the built in animation tab), he seemed to simply ignore gravity (though he still reaction to things hitting his collider).

https://vine.co/v/MJjlDmiFv0V

I took a quick video of this behavior. You can see that he falls to the ground naturally at the beginning, but when the world rotates, he kinda does his own thing (ignore the paranoid sun, that's supposed to do that).

There are no scripts on the block guy, just a the following modules:

alt text

2014-04-14 19_14_25-clipboard.png (46.3 kB)
Comment
Add comment · Show 5
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 Benproductions1 · Apr 15, 2014 at 04:03 AM 0
Share

Does the animation by any chance animate the global position of the object?

avatar image justaleaf · Apr 15, 2014 at 05:38 AM 0
Share

It does, now that you mention it. It's using global transforms. Can I switch that to local, somehow, within the animation panel?

avatar image Pyrian · Apr 15, 2014 at 05:00 PM 0
Share

There doesn't seem to be a way to do it within the animation panel. I've spent quite a few hours painstakingly moving keyframes from one curve to another... Grr.

What you CAN do, though, is make a parent for your animated object and maybe copy the collider and rigidbody into that (or not, if you need the collider animated). Then, your animation will work on local space without having to redo the object tree in the animation pane ("animation pain", lol). Note that this may break your global transforms, so make sure they're relative to 0 ins$$anonymous$$d of relative to the global coordinates after you've made the move.

avatar image Benproductions1 · Apr 15, 2014 at 09:21 PM 0
Share

You can't have "local" transformations of the "global" coordinates because you wouldn't have any sort of reference frame, so either the animations or your transformations would screw up. What @Pyrian suggested is a pretty good workaround.

avatar image justaleaf · Apr 16, 2014 at 12:18 AM 0
Share

@Pyrian - Yes! Putting the collider and rigidbody on an empty object and then putting the sprite renderer and animator on the child object works great.

Note! If you compose the animation while the controller is already parented, it seems to record the tranforms with the local origin. So I just remade the anims and now I'm in business!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by justaleaf · Apr 16, 2014 at 01:16 AM

If someone has a better option, I'm all ears, but as @Pyrian noted in the comments, the following solution seems to work well.

Import your sprite as per usual, setting up your collider and Rigidbody, scripts that effect physics, etc. The collider wraps to the sprites dimensions which will save just a little time.

Then, remove the sprite renderer component from the object, and add the sprite as a child.

So, in my project the parent looks like:

alt text

And the child looks like:

alt text

Now that the child is inheriting it's parents transforms, you should be able to add/create animations freely, working from the transforms relative to the child.


2014-04-15 18_06_30-unity - test-level1.unity - [week1] ballsout - pc, mac & linux standalone_.png (26.2 kB)
2014-04-15 18_06_49-unity - test-level1.unity - [week1] ballsout - pc, mac & linux standalone_.png (26.1 kB)
Comment
Add comment · Show 1 · 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 Benproductions1 · Apr 16, 2014 at 01:57 AM 0
Share

Don't know whether it will screw up the rest of your animation, but setting the animation mode to additive might also work. I'm not able to test it right now though.

avatar image
-1

Answer by ReContraChanfle · Apr 15, 2014 at 05:49 AM

have you tried with the "Animate Physics" in your Animator Inspector.

Comment
Add comment · Show 2 · 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 justaleaf · Apr 15, 2014 at 09:14 PM 0
Share

Yeah, it's pretty funny to watch. But it's not compatible to gravity.

avatar image Benproductions1 · Apr 15, 2014 at 09:22 PM 0
Share

AnimatePhysics allows animations to have a physical effect, not the other way around.

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

23 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

Related Questions

Unity 2D gravity 1 Answer

Need help on my script to calculate gravity for a mass 1 Answer

Move rigidbody whilst keeping it upright 1 Answer

Check if 2D Player is grounded with Physics2D.Linecast 1 Answer

[Complex] How to move the player similar to character controller while also applying rigidbody physics vectors 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