So I created this third person controller script based on the camera position, but my problem is that the object is going right through the floor when moving because I am using translate for movement.
Based on the code below, how would I stop movement in the Y axis?
void Update() {
Vector3 moveSideways = cameraObject.transform.right * strafeSpeed * Time.deltaTime;
if(Input.GetAxis("Horizontal") == 1){
transform.Translate(moveSideways);
}
if(Input.GetAxis("Horizontal") == -1){
transform.Translate(-moveSideways);
}
Vector3 moveForward = cameraObject.transform.forward * movementSpeed * Time.deltaTime;
if(Input.GetAxis("Vertical") == 1){
transform.Translate(moveForward);
}
if(Input.GetAxis("Vertical") == -1){
transform.Translate(-moveForward);
}
}