3D dodge animation problem
This is for my top down isometric 3d game, I have some problems with the dodge/roll, I don't even know if I implemented it the right way, I tried every way possible, state machine, animation events, coroutines, checking if animations end etc. Nothing works as It should, the coroutine aproach works the best.. but I still have one problem.
void Update()
{
direction.x = Input.GetAxis("Horizontal");
direction.z = Input.GetAxis("Vertical");
if (direction.sqrMagnitude > 1.0f)
direction.Normalize();
timer -= Time.deltaTime;
//timer = 0.3f, can only dodge every 300ms
if (time > timer) {
if (Input.GetButtonDown("Jump")) {
roll = true;
timer = time;
}
}
}
void FixedUpdate() {
Gravity();
Roll();
//if the player is rolling stop other movements
if (canMove) {
Move();
//rotate player to face the cursor
Rotate();
} else {
//rotate player to facing direction
transform.rotation = Quaternion.LookRotation(lastDirection);
movement = Vector3.zero; //reset movement vector when rolling
}
}
private void Move() {
movement = (forward * direction.z) + (right * direction.x);
controller.Move(movement * movSpeed * Time.deltaTime);
if (movement != Vector3.zero) {
lastDirection = movement;
}
UpdateAnim(movement);
}
private void UpdateAnim(Vector3 direction) {
if(direction.x != 0 || direction.y != 0) {
anim.SetBool("running", true);
}
else {
anim.SetBool("running", false);
}
}
private void Roll() {
if (roll) {
StartCoroutine(RollRoutine());
}
IEnumerator RollRoutine() {
float elapsedTime = 0f;
while(elapsedTime < duration) {
controller.Move(lastDirection.normalized * Time.deltaTime);
elapsedTime += Time.deltaTime;
}
canMove = false;
anim.SetBool("rolling", true);
yield return new WaitForSecondsRealtime(0.55f);
anim.SetBool("rolling", false);
roll = false;
canMove = true;
}
The problem is when I spam space to roll, the player would sometimes stop the animation, repeat it in place etc. and glitch out, even tho I have a timer on the space bar so it cannot be spammed, even If I bump it up to only let space be pressed every 1 or 2 seconds, it still happens.
This is the problem, the character does that.. I was spamming space the entire time in the video: https://youtu.be/ne1AjrQdo2Y
Your answer
Follow this Question
Related Questions
Rolling Animation Problem 0 Answers
Problem: My animations like rolling do not roll far at all 0 Answers
Offset Reload Animation to Fit New Model 0 Answers
Can unity animate 3D objects? 0 Answers