- Home /
Question by
iamtheonenoobs · Jul 30, 2019 at 09:53 PM ·
wontwork
why wont my character move
my character was working fine until i added my animator variable, whenever i press a or d it did change the direction but it will only play the animation for a second and my character cant even move up or down or left and right heres the code` using UnityEngine;
public class playercontroller : MonoBehaviour { public float jumpforce; public float speed;
public Animator anim;
public Rigidbody2D rb;
bool facingright = true;
bool isgrounded;
float moveinput;
// Update is called once per frame
void FixedUpdate()
{
moveinput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveinput * Time.deltaTime * speed * 50, rb.velocity.y);
if (facingright == true && moveinput < 0)
Flip();
if (facingright == false && moveinput > 0)
Flip();
if (Input.GetKeyDown(KeyCode.Space) && isgrounded == true)
{
isgrounded = false;
rb.velocity = Vector2.up * jumpforce;
}
}
void Update()
{
anim.SetFloat("speed", rb.velocity.x);
Debug.Log(rb.velocity);
}
void Flip()
{
facingright = !facingright;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
void OnCollisionEnter2D(Collision2D collision)
{
isgrounded = true;
}
} `
Comment
Your answer
Follow this Question
Related Questions
Advert wont play 0 Answers
Unity Won't let me load my projects? 0 Answers
Death Particles won't show where player dies.,Particles won't follow the player. 1 Answer
My player wont jump 1 Answer