I am slowly falling down with the jump animation
Hello everyone, have have some small issue, but i still can't understand, what;s wrong. I have jump system: Character (with capsule collider and rigid body, and they set up properly), Empty gameobject with ray, for detecting is Player grounded Before i added jump animations - everything worked correctly. I have 3 jump animations
Anticipation
Floating
Landing
When Floating is playing - my character falling really slow, without animation I have normal fall speed Here is my code
public class Jump : DragControllerForwad
{
public float jumpHeight = 10f;
public bool isGrounded;
//Character rigid body
public Rigidbody rb;
//Character animator
[SerializeField]
Animator anim;
void Start()
{
rb = transform.Find("animation").GetComponent<Rigidbody>();
anim = transform.Find("animation").GetComponent<Animator>();
}
void Update()
{
RayCasting();
}
// Ray for detecting ground
protected override void RayCasting()
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, .5f))
{
Debug.DrawLine(ray.origin, ray.origin + ray.direction * .5f, Color.green);
if (hitInfo.collider.tag == "Ground")
{
isGrounded = true;
}
else
{
isGrounded = false;
}
}
else
{
isGrounded = false;
Debug.DrawLine(ray.origin, ray.origin + ray.direction * .5f, Color.red);
}
// Code for jump animations
if (isGrounded == true)
{
anim.SetBool("isJump", false);
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpHeight, ForceMode.Impulse);
}
}
else if(isGrounded == false)
{
anim.SetBool("isJump", true);
}
}
}
My animator controller:
Is your animator on the same gameobject as the rigidbody / collider? $$anonymous$$aybe making your animator a child of your player gameobject could fix the problem, I'm not entirely sure and cannot test at the moment, but it might be that your animation is overriding the physics and by making it a child you could avoid that.
I am sorry, but I didn't understand, how to make animator child of a player, thanks for response!
And yeah, animator is on the player, and he has rigb and capsule collider.Idk if it's important, but I have these constraints on rb: freeze position on z, and freezed all kinds of rotation
Answer by unity_lSXJSIZAvqe3Qw · May 28, 2020 at 01:17 PM
I finally found out how to fix it, if you guys will have the same problem - try tu turn off allow root animation in your animator in inspector
Yes but this time the character stops moving with the animation, it is stationary even in the walking animation
Answer by Jakeiiii · May 28, 2020 at 07:46 AM
There doesn't seem to be any clear indication in your code as to when your player is in the "floating" state. There isn't any specific "Float" animation, nor is there a boolean or enum value to check whether it is. And I assume that in the "floating" state you don't want any vertical velocity at all; and also that this "floating" only happens at the peak of your jump, correct? And what is the length of the floating determined by? Is it the length of the animation? The length of the jump button being held down? Once you can define what exactly this "floating" state is and how it functions then I can provide some help as to how to keep the character still in the air during this time.
Yeah, my bad, that's my first time one this forum. Floating - is the period when anticipation ends. In two words - jump end. And untill isGrounded is false, character saves last pose from previous jump animation. When he is "floating" he falls really slow down, and when he hits the ground - landing animation executing. So the main issue - slow falling
Answer by N-8-D-e-v · May 27, 2020 at 09:58 PM
Try editing the gravity scale in the Rigidbody of your player. Or go to the project settings and adjust the default gravity,
Answer by tadadosi · May 28, 2020 at 12:14 PM
Edit: Previous answer: Try moving your Animator away from the Player gameobject, make it a gameobject child. Also make sure that your code finds the animator after you made the change.
New answer: Sorry about the last one. You shouldn't be moving your animator away, you should be creating a new gameobject called player and move all your behaviour and collider in there and leave just the animator in what's your current Player. If you remove the animator from the current player, it will not work because the animator will be looking for the previous hierarchy and will not find it.
So basically:
Rename your current Player to Animator.
Create a new empty object in the same position as the Animator.
Paste all your behaviour and colliders to the new object.
Remove all the behaviour from your Animator.
Make your Animator a child of your new Player.
Test.
I did as you showed me, but after this none of my animations executes
Oops, I know what went wrong, I'll fix my answer in a moment, sorry about that.