- Home /
Player can't move, Boxcast Problem
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);
}
}
Answer by Deonisos69 · Jul 25, 2021 at 02:28 PM
Nevermind guys, my Player was on the ground layer.
She was constantly colliding with herself.
Your answer
Follow this Question
Related Questions
Odd behavior when circle collider is supposed to bounce off wall 1 Answer
Box collider 2D failing when far from location 0,0,0 3 Answers
Box pushes another box while it's supposed to move on top of it 0 Answers
Issues with Character Controller moving Enemies 1 Answer
How Do I Make a Rigidbody2d keep its force and move at a consistent speed? 2 Answers