Hi all and thanks for reading.
I am trying to implement a basic (or so I thought!) camera system to use in my game. Essentially I want the camera to follow a game object at a fixed distance (in this case a rolling ball) controlled by the player. I also want the player to be able to rotate the camera around the ball, and the movement vectors supplied by the player input to change accordingly (i.e. so forward is always in the direction the camera is facing).
So far I have managed to get the camera following the ball, the rotation working and the player input working. I did this by using the transform.forward property of the camera and using that (and multiplications thereof) as the vectors in the transform.AddForce() method on the ball. This is sort of working okay, but the problem that I am having is that if I rotate the camera to be above the ball, the ball moves forward much slower, & vice versa if I position the camera immediately behind the ball it moves extremely fast. I understand that this is because the x (or z, depending on which way the camera is facing) components of the transform.forward vector are obviously lessened the closer the vector gets to the y-axis, but I want a smooth propulsion regardless of how steep the angle of the camera is - essentially, I only want the direction of the vector & not its magnitude. (I think…)
I’ve tried normalising the transform.forward vector by dividing everything by its component and ending up with a unit vector, but that only works when the camera is positioned precisely in one direction, else the ball just propels equally by a unit of one in every direction.
I’m really stumped at this point and am not sure whether I’m barking up the wrong tree wrt normalising the vectors. Would anyone be able to give me some pointers as to where I’m going wrong - either in my thinking or my coding! (Or, more likely, both!) I am quite new to coding and such and I know that this is probably a very nooby question but I’d really appreciate any help you’d be able to give me.
Thanks for reading.
Sam