#is there a way i can replicate this
1 messages ยท Page 1 of 1 (latest)
ignore the armor change
what im trying to do is make the character seemlessly transition to shooting while moving when the x key is pressed and one of the arrow keys are moving
here is my animator controller:
here is the updated script
when i try to do it i get this result:
any tips?
Use a synced animation layer that has the shooting variants of all the animations
let me give it a shot
but once i do that
how can i trigger said synced animation layer
Animation Layers are not triggered, they are blended to using Weight
when should i trigger the weight?
when the shoot button is pressed while the character is moving?
If your layer has the shooting variants, then you would set weight to 1 when your character shoots, and set it back to 0 when you want the the character to stop pointing the weapon, so likely after a delay
heres the code for this:
private IEnumerator MoveShoot() {
animator.SetLayerWeight (1,1);
newProjectile = Instantiate(bulletPrefab,firePoint.position,firePoint.rotation);
yield return new WaitForSeconds(1.5f);
animator.SetLayerWeight (1,0);
animator.SetLayerWeight (0,1);
}
suppose i stop repeatedly pressing the key, how can i properly and smoothly reverse the animation back to the non shooting animation
because when i keep pressing the shoot key
first time its fine
but it keeps turning on and off
Since you're calling the layerweight change via coroutine after 1.5 seconds, that'll happen even if you start shooting again
The delayed method will interrupt the second shot
I prefer to use timer variables instead of coroutines because they're much more intuitive to pause and check if they're running
@vague kettle:
private void MoveShoot() {
Debug.Log("Ur shooting while moving!!!");
timerIsRunning = true;
seconds = 2;
animator.SetLayerWeight (1,1);
newProjectile = Instantiate(bulletPrefab,firePoint.position,firePoint.rotation);
if (timerIsRunning)
{
if (seconds > 0)
{
seconds -= Time.deltaTime;
Debug.Log(seconds);
}
else
{
Debug.Log("Ur done damn");
animator.SetLayerWeight(1, 0);
seconds = 0;
timerIsRunning = false;
}
}
}
everytime this method runs it always gets stuck at 1.996175
and this method is called at the update macro
if(Input.GetKeyDown(KeyCode.X) && animator.GetFloat("Speed") > 0.01 && animator.GetBool("IsInAir") == false) {
MoveShoot();
animator.SetTrigger("isShootingMoving");
}
no matter what i do, it doesnt actually get to zero