Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question my animation does this weird bobby thing

Discussion in 'Animation' started by NintendoAsh12, Jan 8, 2023.

  1. NintendoAsh12

    NintendoAsh12

    Joined:
    Feb 15, 2021
    Posts:
    86
    whenever I preview my animation in the editor the object moves as normal but as soon as I run my script and play my animation it does this little bobby thing like a sudden up-down movement here is my script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SpikeLogTrigerEnter : MonoBehaviour
    6. {
    7.     [SerializeField] private Animator Animator;
    8.     private void OnTriggerEnter2D(Collider2D collision)
    9.     {
    10.         if (collision.CompareTag("Player"))
    11.         {
    12.             Animator.SetBool("JOHNisIN", true);
    13.             Animator.SetBool("isUP", true);
    14.             Animator.SetBool("JOHNisnotIN", false);
    15.         }
    16.  
    17.         if (collision.CompareTag("SpikeLogisUP"))
    18.         {
    19.             Animator.SetBool("isUP", false);
    20.             Debug.Log("Down");
    21.         }
    22.     }
    23.     private void OnTriggerExit2D(Collider2D collision)
    24.     {
    25.         Animator.SetBool("JOHNisnotIN", true);
    26.         Animator.SetBool("JOHNisIN", false);
    27.         Debug.Log("exit");
    28.     }
    29.  
    30. }
    31.  
    Here's a video showing it in action


    here are some images of my transitions: https://drive.google.com/drive/folders/1zk7QaB0DuavY3d-5vJi-I8fXfO7dpJtb?usp=sharing
     
  2. jn97342

    jn97342

    Joined:
    Jan 4, 2023
    Posts:
    41
    Confused on your question, what are you trying to do?

    Try messing around with HasExitTime or your transition durations, but please clarify what you are trying to achieve. Do you want the spike to fully go down and disappear, and after a certain time, come back up again?
     
  3. jn97342

    jn97342

    Joined:
    Jan 4, 2023
    Posts:
    41
    Also one other question, shouldn’t the default state have the spike down? Why is there a separate Animation for the Spike down and a different one as a default state. Set the SpikeDown as the Default Animation State, and have two different transitions between SpikeDown (The Default transition) and SpikeUp.