When i add my box collider2d to player positions go crazy i have rigidbody 2d on
SCRIPT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class haha : MonoBehaviour
{
public float speed = 10;
private Animator anim;
private Rigidbody2D rb;
public float jump;
float moveVelocity;
bool grounded = true;
private void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
//Jumping
if (Input.GetKeyDown (KeyCode.Space) || Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.Z) || Input.GetKeyDown (KeyCode.W))
{
if(grounded)
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
}
}
moveVelocity = 0;
//Left Right Movement
if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A))
{
moveVelocity = -speed;
}
if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D))
{
moveVelocity = speed;
}
GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveVelocity, GetComponent<Rigidbody2D> ().velocity.y);
float moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector3(moveInput * 100, rb.velocity.y);
if (moveInput == 0)
{
anim.SetBool("isRunning", false);
}
else
{
anim.SetBool("isRunning", true);
}
}
void OnTriggerEnter2D()
{
grounded = true;
}
void OnTriggerExit2D()
{
grounded = false;
}
}