- Home /
Question by
TheBudmanman · Feb 08, 2018 at 02:16 PM ·
animatorscript.
Animation bool not working
Hi, I had a grounded check that was working before but not longer is. I also had a modified version of the grounded check to see if the player was moving right.
The values appear checked when they should be in the script's box:
But they do not appear in the animator, so they don't trigger the animations:
Here is the main movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Basic_Movement : MonoBehaviour {
public float maxSpeed = 4;
public float speed = 50f;
public float jumpPower = 150f;
public bool grounded;
public bool right;
private Rigidbody2D rb2d;
private Animator anim;
private bool player;
void Start () {
rb2d = gameObject.GetComponent<Rigidbody2D> ();
anim = gameObject.GetComponent<Animator>();
}
void Update () {
anim.SetBool("Grounded", grounded);
anim.SetFloat("Speed", Mathf.Abs(rb2d.velocity.x));
anim.SetBool("Right", right);
if (Input.GetAxisRaw("Horizontal") > 0.1f)
{
right = true;
}
if (Input.GetButtonDown("Jump") && grounded)
{
rb2d.AddForce(Vector2.up * jumpPower);
}
}
void FixedUpdate()
{
Vector3 easeVelocity = rb2d.velocity;
easeVelocity.y = rb2d.velocity.y;
easeVelocity.z = 0.0f;
easeVelocity.x *= .75f;
float h = Input.GetAxisRaw("Horizontal");
{
rb2d.velocity = easeVelocity;
}
rb2d.AddForce((Vector2.right * speed) * h);
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
}
}
and here is the grounded check's script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundCheck : MonoBehaviour {
private Basic_Movement player;
void Start()
{
player = gameObject.GetComponentInParent<Basic_Movement>();
}
void OnTriggerEnter2D(Collider2D col)
{
player.grounded = true;
}
void OnTriggerStay2D(Collider2D col)
{
player.grounded = true;
}
void OnTriggerExit2D(Collider2D col)
{
player.grounded = false;
}
}
nothere.png
(9.6 kB)
workshere.png
(17.4 kB)
Comment
Your answer
Follow this Question
Related Questions
How to use Animator Override Controler in script? 0 Answers
Animation State Machine Script Control Issue 1 Answer
2D animation diferent right and left 0 Answers
blend tree animation through script? 0 Answers