Hello everyone!
I’m having a bit of a problem with my movement. I’m trying to cast a BoxCast on the x Axis so i can know if my player can go in that direction. I’m doing that so my player doesn’t clip into the walls when using transform.Translate (I’m setting the rigidbody velocity.x to zero when he would hit a wall and prevent further moving).
But when I start the game my character can’t move.
If I move the Boxcast origin.y above she can move, but stops when there is platform above her.
If I remove the BoxCast she can move without a problem, so the problem should be with the Boxcast.
Anyone got an Idea?
Thx in advance
//Moving
protected void Run(Vector2 input)
{
hit = Physics2D.BoxCast(new Vector2(transform.position.x,transform.position.y+0.3f),coll.size,0, new Vector2(input.x, 0), Mathf.Abs(input.x*Time.deltaTime), LayerMask.GetMask("Ground"));
if (anim.GetBool("canMove")&&hit.collider==null)
{
// ribo.velocity = new Vector2(input.x, ribo.velocity.y);
transform.Translate(new Vector3(input.x*moveSpeed*Time.deltaTime,0,0));
anim.SetBool("isRunning", true);
if (input.x > 0)
{
transform.localScale = (new Vector3(1, 1, 1));
}
if (input.x < 0)
{
transform.localScale = (new Vector3(-1, 1, 1));
}
}
if (hit.collider != null)
{
ribo.velocity = new Vector2(0, ribo.velocity.y);
}
}
