I have a cube and it's on the ground and there are two walls (Plane) next to the ground.
Like in the image there is a ground and in side there is a wall. Here is my code:
void Update() {
transform.Translate(userDirection * speed * 14f * Time.deltaTime);
transform.Translate(mSpeed * Input.GetAxis("Horizontal") * 2 * Time.deltaTime, 0f, mSpeed * Input.GetAxis("Vertical") * 2 * Time.deltaTime);
if (Input.touchCount == 0)
return;
Touch touch = Input.GetTouch(0);
float originalY = transform.position.y;
float cameraZ = Camera.main.WorldToScreenPoint(transform.position).z;
if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Began) {
Vector3 screenPoint = new Vector3(touch.position.x, touch.position.y, cameraZ);
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(screenPoint);
worldPoint.y = originalY;
transform.position = worldPoint;
}
}
My cube goes through the side walls, but on laptop it works perfectly, and on android device my cube goes through the side walls. Can anyone please tell why is my cube is going through side walls? Any help is appreciated!