- Home /
How to stop a camera clipping through walls?
So I'm making an FPS style game but I can't quite figure this out. I'm just using the camera as the player's view, as it was going to be hard to use a character model to do it. I've looked on a bunch of other posts, but couldn't quite figure out how to do it when I'm using translate as opposed to rigidbodies or character controllers.
Here's my player controller script: void Update() {
forwardInput = Input.GetAxis("Vertical"); horizontalInput = Input.GetAxis("Horizontal"); mouseX = Input.GetAxis("Mouse X"); mouseY = Input.GetAxis("Mouse Y");
if(transform.position.y < yBound || transform.position.y > yBound)
{
transform.position = new Vector3(transform.position.x, yBound, transform.position.z);
}
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput);
transform.Rotate(new Vector3(-mouseY, mouseX, 0));
float z = transform.eulerAngles.z;
transform.Rotate(new Vector3(0, 0, -z));
}
Would it just be easier to use rigidbodies or is there a way to do this by adjusting the transform?
Answer by swanne · Nov 03, 2020 at 03:53 PM
Hey,
Check this tutorial series out. Even if it's not exactly what you want to create, you'll learn some sweet tips - https://www.youtube.com/watch?v=MAAxL6Q_ElE&list=PL6PsTmPNvw0eZirNDjO8dL0Y6X0ZFGaMt∈dex=1
Your answer
![](https://koobas.hobune.stream/wayback/20220613015119im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Third Person Camera Controller Jitter 1 Answer
Camera smooth transistion 2 Answers
Keyboard / Mouse control for FPS 0 Answers
Movie Textures. 0 Answers