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 Runemark · Jun 04, 2013 at 02:57 PM · rigidbodymecanimgravity

No gravity with mecanim...?

Hi! First, sorry for my english!

I just started to play with unity. I really like it. I was doing several tutorials. Now i trying to make a 3rd person multiplayer shooter, with mecanim.

My animations works well, and after 10 hours it is syncronized with the other clients. Awesome! but I have a very irritating problem: the gravity.... (I think)

Here is the video about it: http://youtu.be/o1-MXXpq2NA So the main problem is that the character dont fall down, and can run in the Y axis. The other problem is, if I look down or up with the mouse, the character leans that way... Any idea how could I solve this?

Solution: I changed in the Physics Manager (Edit/Project Settings/Physics) the gravity (Y axis) from -9,81 to -50.

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

7 Replies

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

Answer by TonyLi · Jun 04, 2013 at 04:11 PM

I can't make out all of the details of the Hierarchy and Inspector tabs, so these are my best guesses. Can you provide a screenshot of the fully-expanded components in the Inspector tab?

Gravity: Does gravity work without the animator component? Try disabling the animator component and any scripts that rely on it. Then press Play and, in the Scene View, raise the character off the ground. The rigidbody (with Use Gravity ticked) should make the character fall.

Check the layers, including any colliders attached to any child objects. It's possible that a child object is colliding with the character's capsule collider, preventing the capsule collider from falling.

Camera: Keep the camera and character separate. Don't make one a child of the other. If one is a child of the other, then when the parent's rotation changes, the child will also rotate.

For both of these issues, examine the scripts provided with the Mecanim Examples project (available on the Asset Store). Compare your scripts to see the differences.

Comment
Add comment · Show 13 · 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 Runemark · Jun 04, 2013 at 04:50 PM 0
Share

Hmm... Yes, if I turn off the Animator component, the character falls down properly. $$anonymous$$ore specifically if I turn on this component, and I turn off the "Apply Root $$anonymous$$otion" option, it works well. Sadly it is not yet a solution, becouse if I do so, my character control won't work.

avatar image TonyLi · Jun 04, 2013 at 06:31 PM 1
Share

Okay, we're narrowing down the problem. :-) Try these ideas:

  1. In the animation importer, under Root Transform Position (Y), tick Bake into Pose and select Based Upon > Original. Then click Apply.

  2. If that doesn't work, your animation file might have a problem with gravity, which is setting Animator.gravityWeight wrong.

  3. Finally, consider temporarily switching to a CharacterController ins$$anonymous$$d of a CapsuleCollider+Rigidbody. If this works, then maybe the Animator isn't playing nicely with your rigidbody setup.

avatar image Runemark · Jun 04, 2013 at 07:00 PM 0
Share

Ok. I have 2 kind of animations: Raw $$anonymous$$ocap data for $$anonymous$$ecanim and from the tutorial video. Now in the Animator, I only got from the second one. I modified all these animations RTransform Position Y as you said.

During this time, I solved my camera problem. I had a $$anonymous$$ouseLock script and forgot to change from xy direction to only x. So now my character don't leans down or up.

Back to the gravity: I upload one more video: http://youtu.be/wzDJeaG60dA

Gravity is working.. but not really as I want :D

avatar image Runemark · Jun 04, 2013 at 10:31 PM 0
Share

I checked the Animator.gravityWeight and it was 1... btw I don't really know, if its good or not... in the tutorial scene, it is 1 too... $$anonymous$$y check was:

 Debug.LogWarning(anim.gravityWeight);

Did I this well?.. :)

I tried change to character controller. I removed the BotControlScritp.cs, the Capsule Collider and the Rigidbody. And add the default fpsinput to the character prefab. Gravity was good, but withouth any animation...

avatar image Chronos-L · Jun 05, 2013 at 01:16 AM 0
Share

I faced a similar problem in using the additive move-forward animation with gravity (http://answers.unity3d.com/questions/442277/mecanim-and-rigidbody.html).

In my case, I was try to animate a simple legless NPC, and I used Generic $$anonymous$$ecanim for it, I tried almost all possible setting but none of them works. However, when I play with the example provided by Unity, I noticed that the gravity is not working once I switch from Humanoid animation to Generic animation, it is possible for the gravity to not work in Generic mode?

Show more comments
avatar image
3

Answer by Jeff-Kesselman · Oct 25, 2013 at 09:57 PM

I had this problem.

Make sure "apply root motion' is NOT checked in your animator.

If it is then I think the animator applies the in-place position after every frame and puts it back to previous Y. Anyway, unticking it solved my problem.

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
avatar image
2

Answer by vet-cat · Aug 31, 2014 at 03:17 PM

add CharacterController add script ApplyGravityCharacter.cs

using UnityEngine; using System.Collections;

public class ApplyGravityCharacter : MonoBehaviour { public float Gravity = 20f; public bool UseGravity = true; private CharacterController characterController;

 void Awake()
 {
     characterController = GetComponent<CharacterController>();
 }

 void Update () 
 {
     if (!characterController.isGrounded && UseGravity)
     {
         characterController.SimpleMove(gameObject.transform.up * Gravity * Time.deltaTime);
     }
 }

}

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 Martelol · Mar 11, 2015 at 07:21 PM 0
Share

Thanks vet-cat, i've never give much attention to the character controller, and i was trying to create an ragdoll character but i was having a problem to apply the gravity on the character, because i was trying both add an rigidbody to the main object and he always fall through the ground and add an collider and the character was rotating like an retard, but adding this script managing the character controller i was able to apply the gravity to my ragdoll character and changing from mecanim to ragdoll easily!! thanks again!!

avatar image WheresMommy · Apr 10, 2015 at 04:53 PM 0
Share

As I am not able to vote yet, I gotta say, thank you very much for this easy solution. I was mixing root animation with controller.move, which did weird things. No it floats perfectly over the ground ;)

avatar image
0

Answer by Anton1274 · May 14, 2015 at 03:39 PM

Yeah the problem is with the Animator Apply Root Motion, if is checked true there is no Gravity over the RigidBody if is set false the Gravity will affect the RigidBody. Check if the Collider is Grounded and modify this property

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
avatar image
0

Answer by Jon Jennings · Jul 06, 2015 at 05:59 PM

I changed my routine which updates the root motion, such that it only applies the X and Z components of the root motion and leaves the Y component as applied by the ridgidbody

void OnAnimatorMove(){

     tempvector = player_rigid_body.velocity;
     tempvector.x = anim.deltaPosition.x / Time.deltaTime;
     tempvector.z = anim.deltaPosition.z / Time.deltaTime;
     player_rigid_body.velocity = tempvector;
     player_rigid_body.rotation = anim.rootRotation;
 
 }
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
  • 1
  • 2
  • ›

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

22 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

Related Questions

mecanim and rigidbody gravity effect doesnt work 1 Answer

My Mecanim-Generic is screwing with the gravity 2 Answers

Player with Rigidbody gravity and root motion bobs up and down into the terrain 0 Answers

Gravitational pull without losing speed 1 Answer

RigidBodys Suddenly Heavier 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