Hello !
I am facing an issue with a game i’m trying to build in 3D :
My player and my walls have a rigidbody and a box collider. Here is the script in my player object :
public class PlayerMovements : MonoBehaviour
{
public Rigidbody rb;
void Start()
{
}
void Update()
{
foreach (Touch t in Input.touches) {
Vector3 translation = new Vector3(t.deltaPosition.x, 0, t.deltaPosition.y) * Time.deltaTime;
// divide 'translation' by Input.touchCount to remove the speed boost ability
transform.Translate(translation);
}
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.name == "obstacle")
rb.velocity = Vector3.zero;
}
}
As you can see, the player is controlled by finger swipes.
My issue is that when we try to push the player in a wall, it goes slightly into it before moving back. Worst : the player can get completely trough the wall if we swipe fast enough.
I’ve searched trough a lot of topics but i haven’t find any good answer. Does someone have a solution to this ?
Thanks