Yeah when I found out about blend trees my whole life changed! It's nice to group things together with them :-) keeps it much tidier! I've just planned the animations for my future platformer series which uses all transitions instead of blend trees, so it can work well for simple games!
The only thing this is really showing me, is how far away I am, from typing something in VS and go back into unity... and its just working as I want it to...
when pressing for diagonal movement does your diagonal idle movements show because Unity seems to register the last button released and snap them to either left right up or down
I had this problem too! It is possible to get it to end diagonally, but it’s due to it reading either the up or side like 0.01% more than the other, so it isn’t a perfect diagonal input. To get it to stay diagonal, you could make the threshold for changing directions higher than 0 so that it stores the last move before exactly 0 for both x and y. I tried to find an easy fix for this video, but couldn’t find one without it getting more complicated, so left it out! Here’s a thread I found on other peoples solutions too: discussions.unity.com/t/8-way-movement-diagonal-idle-issues/172804 It seems to work better with a controller since the input is more precise! But keyboard can be harder to get exact. Good luck!! I’ll let you know if I find another fix in the future!
@@GameCodeLibrary Is this what you mean? Vector2 currentMoveInput = move.ReadValue(); if ((currentMoveInput.x == 0 && currentMoveInput.y != 0 || currentMoveInput.x != 0 && currentMoveInput.y == 0) && (direction.x != 0 && direction.y != 0)) { lastMoveDirection = direction; } // Create a direction vector based on the input direction = move.ReadValue();
I got an error thats quote "Assets\PlayerMovment.cs(56,45): error CS1061: 'Vector2' does not contain a definition for 'Magnitude' and no accessible extension method 'Magnitude' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)" and i dont know how to fix it. I have no coding experience and i put the anim.SetFloat("MoveMagnitude",input.Magnitude); like you did in your video but its giving me this error.
didnt work for me it keeps the animation state play on my idle down animation instead of every input direction edit: nvm i forgot to set the blend types to last move
I got this error and I dont know how to fix it NullReferenceException: Object reference not set to an instance of an object Move.FixedUpdate () (at Assets/Scripts/Move.cs:34)
If you double click on your error it takes you to the line with the problem! Line 34 in our script is the rigidbody. Make sure you select your player and drag the rigidbody into the rigidbody slot. Or - in your Start function do: rb = GetComponent();
Cool to know about these blend trees. Last time I messed around with the animator I made a lot of transitions to different animations manually
Yeah when I found out about blend trees my whole life changed! It's nice to group things together with them :-) keeps it much tidier!
I've just planned the animations for my future platformer series which uses all transitions instead of blend trees, so it can work well for simple games!
Yayy, another vid
really nice tutorial, this helped me to understand how blend trees work and now I will use this in my own project. thank you so much!!
You’re welcome!! I’m so glad it helped 😊 I love using blend trees!
Your voice is so soothing, Love the tutorials!
Glad you enjoy :-) Thank you!!
The only thing this is really showing me, is how far away I am, from typing something in VS and go back into unity... and its just working as I want it to...
when pressing for diagonal movement does your diagonal idle movements show because Unity seems to register the last button released and snap them to either left right up or down
I had this problem too! It is possible to get it to end diagonally, but it’s due to it reading either the up or side like 0.01% more than the other, so it isn’t a perfect diagonal input.
To get it to stay diagonal, you could make the threshold for changing directions higher than 0 so that it stores the last move before exactly 0 for both x and y.
I tried to find an easy fix for this video, but couldn’t find one without it getting more complicated, so left it out!
Here’s a thread I found on other peoples solutions too: discussions.unity.com/t/8-way-movement-diagonal-idle-issues/172804
It seems to work better with a controller since the input is more precise! But keyboard can be harder to get exact.
Good luck!! I’ll let you know if I find another fix in the future!
I need this fix also.. even chat gpt didn't help :(
@@dexi7205 did you get it to work?
I found a solution. It's not great, but it's okay.
/////////////////////////////////////////////////////////////////////////////////////
public float speed;
private bool isMoving = false;
private Rigidbody2D rb;
private Animator animator;
private void Awake()
{
rb = GetComponent();
animator = GetComponent();
}
private void FixedUpdate()
{
Movement();
}
private void Movement()
{
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
Vector2 move_dir = new Vector2(moveX, moveY).normalized;
if (!isMoving)
{
StartCoroutine(CheckIdle());
rb.velocity = Vector2.zero;
}
else
{
rb.velocity = move_dir * speed;
}
}
private IEnumerator CheckIdle()
{
isMoving = true;
yield return new WaitForSeconds(0.1f);
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
if (Mathf.Abs(moveX) > 0 || Mathf.Abs(moveY) > 0)
{
animator.SetFloat("x", moveX);
animator.SetFloat("y", moveY);
animator.SetBool("is_moving", isMoving);
StartCoroutine(CheckIdle());
}
else
{
isMoving = false;
animator.SetBool("is_moving", isMoving);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@GameCodeLibrary
Is this what you mean?
Vector2 currentMoveInput = move.ReadValue();
if ((currentMoveInput.x == 0 && currentMoveInput.y != 0 || currentMoveInput.x != 0 && currentMoveInput.y == 0) && (direction.x != 0 && direction.y != 0))
{
lastMoveDirection = direction;
}
// Create a direction vector based on the input
direction = move.ReadValue();
I got an error thats quote "Assets\PlayerMovment.cs(56,45): error CS1061: 'Vector2' does not contain a definition for 'Magnitude' and no accessible extension method 'Magnitude' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)" and i dont know how to fix it. I have no coding experience and i put the anim.SetFloat("MoveMagnitude",input.Magnitude); like you did in your video but its giving me this error.
Need to be a lowercase M on magnitude
Code is case sensitive! :-)
Very good at simplifying things ,keepup 👍
That's the goal! Sweet and simple - thanks so much!
didnt work for me it keeps the animation state play on my idle down animation instead of every input direction
edit: nvm i forgot to set the blend types to last move
I got this error and I dont know how to fix it
NullReferenceException: Object reference not set to an instance of an object
Move.FixedUpdate () (at Assets/Scripts/Move.cs:34)
If you double click on your error it takes you to the line with the problem!
Line 34 in our script is the rigidbody.
Make sure you select your player and drag the rigidbody into the rigidbody slot.
Or - in your Start function do:
rb = GetComponent();
@@GameCodeLibrary thanks it works but now Im getting 999+ warnings saying MoveX, MoveY, LastMoveX, LastMoveY and MoveMagnitude does not exist
Already fixed it thanks
Nice Tutorial
nice tutor but it took 3 days ytb to notify me that u just posted a new clip 😂
Haha oh no! Maybe I should make a community post each time I post a new vid... but I don't want to be annoying 🤔
Thx!
2d Ai and 3d