|
Post by mostlyhuman on Jun 15, 2019 7:06:57 GMT
How can I enable/disable a player's ability to move or rotate the character while certain attack animations are playing or perhaps also slow rotation/movement while some attack animations are playing? Thanks in advance!
|
|
|
Post by mostlyhuman on Jun 17, 2019 1:09:13 GMT
I modified the vMeleeAttackControl state machine behavior script to have both an allowMovementBefore and allowMovementAfter, and also added options to allow or disallow both movement or rotation but its still not working and we arent sure why. Here is the code we created for the SMB if (stateInfo.normalizedTime % 1 > allowControlBefore && stateInfo.normalizedTime % 1 < allowControlAfter)
{
isAttacking = true;
mFighter.ContinueAttack(); Debug.Log("Middle");
}
else if (stateInfo.normalizedTime % 1 < allowControlBefore)
{
isAttacking = false;
if (mFighter != null)
mFighter.OnDisableAttackCustom(allowRotationBefore, allowMovementBefore); Debug.Log("Beginning");
}
else if (stateInfo.normalizedTime % 1 > allowControlAfter)
{
isAttacking = false;
if (mFighter != null)
mFighter.OnDisableAttackCustom(allowRotationAfter, allowMovementAfter); Debug.Log("End");
}
and then here is the corresponding methods we created in vMeleeCombatInput public virtual void OnDisableAttackCustom(bool allowRotation, bool allowMovement)
{
cc.lockRotation = allowRotation;
cc.lockMovement = allowMovement;
isAttacking = false;
}
public virtual void ContinueAttack()
{
cc.lockRotation = true;
cc.lockMovement = true;
isAttacking = true;
} See anything obvious? We verified that the SMB is running the correct code at the beginning, middle and end for the correct number of frames of the animation but its just not locking and unlocking the rotation and movement as expected.
|
|
|
Post by Invector on Jun 19, 2019 15:08:56 GMT
You have to considerer the transition as well or add a condition '!animator.IsInTransition(0)' And do some debugs to see if it's going through your methods correclty
|
|
|
Post by shadex on Jul 6, 2019 19:50:28 GMT
I modified the vMeleeAttackControl state machine behavior script to have both an allowMovementBefore and allowMovementAfter, and also added options to allow or disallow both movement or rotation but its still not working and we arent sure why. Here is the code we created for the SMB if (stateInfo.normalizedTime % 1 > allowControlBefore && stateInfo.normalizedTime % 1 < allowControlAfter)
{
isAttacking = true;
mFighter.ContinueAttack(); Debug.Log("Middle");
}
else if (stateInfo.normalizedTime % 1 < allowControlBefore)
{
isAttacking = false;
if (mFighter != null)
mFighter.OnDisableAttackCustom(allowRotationBefore, allowMovementBefore); Debug.Log("Beginning");
}
else if (stateInfo.normalizedTime % 1 > allowControlAfter)
{
isAttacking = false;
if (mFighter != null)
mFighter.OnDisableAttackCustom(allowRotationAfter, allowMovementAfter); Debug.Log("End");
}
and then here is the corresponding methods we created in vMeleeCombatInput public virtual void OnDisableAttackCustom(bool allowRotation, bool allowMovement)
{
cc.lockRotation = allowRotation;
cc.lockMovement = allowMovement;
isAttacking = false;
}
public virtual void ContinueAttack()
{
cc.lockRotation = true;
cc.lockMovement = true;
isAttacking = true;
} See anything obvious? We verified that the SMB is running the correct code at the beginning, middle and end for the correct number of frames of the animation but its just not locking and unlocking the rotation and movement as expected. I'm going to assume that all of this is in OnStateUpdate(). So, like invector said, the problem is most likely the transitions. Usually it involves A transition happening before the code can execute. It also can happen if your rotation is slow and your just giving a few frames to rotate.
What are you actually trying to do.... what do you want it to look like. I've personally went down this path and came to the conclusion that allowing rotation early is pointless, as it's not hard to hit the enemy with either lock-on's or just moving free "aiming" the attack, and allowing rotation 5% before it transitions.
I'm thinking you might want to try a aim assist approach instead. Either raycast, or spawn a collider in front of the player, which grabs the nearest enemy, and rotate the player to face the enemy on OnstateUpdate(). Then allow rotation at the end of the animation, before transitioning. One of the problem's i ran into is the character's rotations while animated, looks like it's on ice skates and therefore awful. I liked the look of a very fast rotation right after end damage is called.
|
|
|
Post by mostlyhuman on Jul 6, 2019 19:56:29 GMT
For us it wasnt the transitions, it was something in the stop movement and rotation code. We ended up rewriting most of that code and were able to get it working using basically the same SMB code I posted. If you have played some of the From Software games like most recently Sekiro, once you initiate a melee attack and the animation begins, it will allow you to change the attack direction before the weapon colliders activate, so like during the first part of the swing but before the actual damage starts. The character just does a quick pivot towards the left or right if the player presses in those directions then the attack animation will complete. So this is what we were going for.
|
|