public class playercontroller2d : MonoBehaviour
{
Animator animator;
Rigidbody2D rb2d;
SpriteRenderer spriteRenderer;
//Booleans
public bool isgrounded;
public bool candoublejump;
[SerializeField]
Transform groundcheck;
[SerializeField]
Transform groundcheckl;
[SerializeField]
Transform groundcheckr;
[SerializeField]
private float runspeed;
[SerializeField]
private float putyourfuckingassup;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
}
private void FixedUpdate()
{
if ((Physics2D.Linecast(transform.position, groundcheck.position, 1 << LayerMask.NameToLayer("ground"))) ||
(Physics2D.Linecast(transform.position, groundcheckl.position, 1 << LayerMask.NameToLayer("ground"))) ||
(Physics2D.Linecast(transform.position, groundcheckr.position, 1 << LayerMask.NameToLayer("ground"))))
{
isgrounded = true;
}
else
{
isgrounded = false;
}
{
{
if (Input.GetKey("d"))
{
rb2d.velocity = new Vector2(runspeed, rb2d.velocity.y);
if (isgrounded)
animator.Play("run");
spriteRenderer.flipX = false;
}
else if (Input.GetKey("a"))
{
rb2d.velocity = new Vector2(-runspeed, rb2d.velocity.y);
if (isgrounded)
animator.Play("run");
spriteRenderer.flipX = true;
}
else
{
if (isgrounded)
animator.Play("idle");
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
if (Input.GetKey("space"))
{
if (isgrounded)
{
rb2d.velocity = new Vector2(rb2d.velocity.x , putyourfuckingassup);
animator.Play("jump");
candoublejump = true;
}
else
{
if (candoublejump)
{
candoublejump = false;
rb2d.velocity = new Vector2(rb2d.velocity.x, putyourfuckingassup);
rb2d.AddForce(Vector2.up * putyourfuckingassup);
animator.Play("jump");
}
}
}
}
}
}
}