Hi, my player gets stuck into an object when it collides with it. The player has a rigidbody and the object only has a box collider. When I move the player it has a kind of blocky movement and I want it that way but when it collides with an object it gets stuck Please help me because I’m new to unity and I’ve been stuck on this for weeks. (Here is the script attached to the player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
float speed = 2.0f;
Vector3 pos;
Transform tr;
void Start() {
pos = transform.position;
tr = transform;
}
void Update() {
if (Input.GetKey(KeyCode.D) && tr.position == pos)
{
pos += Vector3.back;
}
else if (Input.GetKey(KeyCode.A) && tr.position == pos)
{
pos += Vector3.forward;
}
else if (Input.GetKey(KeyCode.W) && tr.position == pos)
{
pos += Vector3.right;
}
else if (Input.GetKey(KeyCode.S) && tr.position == pos)
{
pos += Vector3.left;
}
transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}
}