Posts

Showing posts from January, 2022

Dance animation toggled with X key (Unity Animation parameter with third person character controller)

Image
Finally got the animation to trigger on pressing X, though it was impossible to find specific info online. I initially wanted to just have the animation play once on X, but I ran into the problem of how to set the bool parameter that activated the animation back to false.  Eventually, I settled on have the X key toggle the animation, then it was just a matter of having it transition back to idle. The animation is set to loop, so will keep dancing until you toggle it off. // Dancing stuff private int _animIDDance; private bool danceBool=false; ... private void Dance() { if (Input.GetKeyDown(KeyCode.X))         { //Debug.Log("Dance"); //toggle dancing with X key danceBool = !danceBool; _animator.SetBool(_animIDDance, danceBool); _animator.applyRootMotion = danceBool; } }

Floating, sliding character animations in Unity

Image
Well, I got the root motion problem fixed, but then I noticed that the character was sliding around and floating. This can be fixed with the animation import settings: Root Transform Position(Y) + Bake into Pose Based Upon: Original Root Transform Position(XZ) + Bake into Pose Based Upon: Original *I didn't notice much difference in the Based Upon settings this is from the Unity manual Root Transform Position (Y)          Bake into Pose Enable to make vertical root motion be baked into the movement of the bones. Disable to make vertical root motion be stored as root motion.          Based Upon What the vertical root position is based upon.          -  Original Keeps the vertical position as it is authored in the source file.          -  Center of Mass Keeps the center of mass aligned with root transform position.  ...

Root motion scripting in Unity

So, I'm experimenting with the Unity third person controller, with my own character and I want to add an animation that applies root motion, but the other animations don't. private void Dance() { if (Input.GetKeyDown(KeyCode.X))         { //Debug.Log("Dance"); _animator.SetBool(_animIDDance, true); _animator.applyRootMotion = true; }         } related posts I found online https://forum.unity.com/threads/animated-character-jumps-with-physics-root-motion-rigidbody.672427/ https://forum.unity.com/threads/disable-root-motion-on-some-animations.563482/

Flipping a capsule collider along with animation in Unity

Image
I had this weird problem, when I flipped an animation, the capsule collider, which was also animated, was jumping all over the place. Not much help on the forums, but this video really helped: //so I disabled the .flipX //and instead used transform.eulerAngles = new Vector3(0, 180, 0); transform.eulerAngles = new Vector3(0, 0, 0); /// void FixedUpdate()     {         //if moving right         if (flyDirection == FlyDirection.right)         {             // sr.flipX = true;             transform.eulerAngles = new Vector3(0, 180, 0);             if (Time.time - lastDirectionChangeTime < moveTime)             {                 rb.velocity = new Vector2(moveSpeed, rb.velocity.y);             }           ...

referencing another script in Unity

 a basic thing, I seem to always forget two good threads on the topic: https://forum.unity.com/threads/calling-function-from-other-scripts-c.57072/ https://forum.unity.com/threads/passing-a-game-object-reference-into-script.774251/ I have a script KarmaPlayer that has a function I want to call changeKarma(int change) this is a game pickup item that updates the karma value for the player and then deactivates itself // using System.Collections; using System.Collections.Generic; using UnityEngine; public class KarmaPickup : MonoBehaviour {     public int KarmaValue;     KarmaPlayer karmaPlayer; //variable of type KarmaPlayer (the name of the script / class)     void Start()     {         karmaPlayer = GameObject.Find("KarmaText(TMP)").GetComponent<KarmaPlayer>();         //GameObject.Find("name of the game object").         //finds the game object with the script / component ...

scripting text for TextMeshPro in Unity

Found a good post about it: https://forum.unity.com/threads/changing-textmeshpro-text-from-ui-via-script.462250/ pretty simple really, just make sure to use: using TMPro; TextMeshProUGUI (instead of just TextMeshPro) // using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class KarmaPlayer : MonoBehaviour { public int karma; public int startingKarma=100; public int maxKarma; TextMeshProUGUI textbox; // Start is called before the first frame update void Start() { karma = startingKarma; textbox = GetComponent<TextMeshProUGUI>(); printKarma(); } // Update is called once per frame void Update() { } void printKarma() { textbox.text = "Karma" + karma.ToString(); } }

figures in an empty land

Image
 

Hwang Ui-Jo : best of 2021

Image