I found this question, but I'm not sure if it applies to my problem.
I'm hacking together a Pong-style game, and my problem is with the walls (box collider, no rigid body) not completely stopping movement of the player paddle (box collider, yes rigid body.) Sufficiently fast mouse movement eventually moves the paddle through the wall. There is initial resistance, but I would expect Player Paddle
to stop moving abruptly at the wall. How can I make this happen? I'm new to Unity/colliders/game dev.
My player paddle simply moves up and down (Z-axis) with up/down mouse movement:
public class MouseMovement : MonoBehaviour {
public float speed = 10f;
// Update is called once per frame
void Update () {
var translation = Input.GetAxis("Mouse Y") * speed;
translation *= Time.deltaTime;
transform.Translate(0, 0, translation);
}
}
I exported an asset package that reproduces the problem. My problem objects are Player Paddle
, Upper
, and Lower
https://www.dropbox.com/s/yx9svb51nywdvgg/pong-export.unitypackage?dl=0