I have player and walls. When the player hits the wall, its not moving.
Those are codes for moving
void MoveTileBased()
{
transform.position = Vector3.MoveTowards(transform.position, destination, Time.deltaTime * speed);
if (Input.GetKeyDown(KeyCode.W))
{
nextPos = Vector3.forward;
}
if (Input.GetKeyDown(KeyCode.S))
{
nextPos = Vector3.back;
}
if (Input.GetKeyDown(KeyCode.A))
{
nextPos = Vector3.left;
}
if (Input.GetKeyDown(KeyCode.D))
{
nextPos = Vector3.right;
}
if(Vector3.Distance(destination, transform.position) < 0.01f)
{
destination = transform.position + nextPos;
}
}
This is collision script :
private void OnCollisionEnter(Collision collision)
{
player.speed = 0f;
}
Player rigidbody and collider