So I am making a character controller that can fly and attach themselves to different surfaces, allowing them to walk and treat it as it’s new ground. In essence I need the camera to flip and re orientate using the world up override. Simple follow is the only one i see that offers this setting.
However the issue with simple follow is the lazy follow that the camera has with the character, I need the character to reference the camera to allow right/left movement to be relative to perspective. In practice, the character will loop around due to the hard reference to the camera, and as it lags behind it will tie the player to loop around in the spot.
Here is the problem
I tried regulating the direction reference to change when input is made but:
What would anybody suggest I do? this is really annoying
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
While we’re talking about cameras…
Camera stuff is pretty tricky… I hear all the Kool Kids are using Cinemachine from the Unity Package Manager.
There’s even a dedicated Camera / Cinemachine area: see left panel.
If you insist on making your own camera controller, do not fiddle with camera rotation.
The simplest way to do it is to think in terms of two Vector3 points in space:
Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.
Hey thanks for responding, I am using cinemachine, I just realised that I didn’t mention it.
I have the simple follow bind activated.
In my code I am referencing these directions by:
//execute when input exists
if (inputDirection.magnitude > 0.1f)
{
//calculate directions based on definition of up by the perspective of the camera
Vector3 cameraForward = Vector3.ProjectOnPlane(myCamera.transform.forward, myCameraOrientation.transform.up);
Vector3 cameraRight = Vector3.ProjectOnPlane(myCamera.transform.right, myCameraOrientation.transform.up);
I know how the problem is occuring, it’s the slow follow of the camera that causes it to sling around the character as it tries to follow it, as it lags behind the player is also tied to the camera’s right direction therefore causing the player to sling around the camera too, resulting in the loop.
Solution !!
I ended up just using the lock to target with world up, however that setting locks to target with rotation, meaning that when the character rotates the camera will jitter along matching that, so to tackle this I just get an empty transform and make it always match the player position.
Everything else intended will work as intended, and the camera won’t jitter around the player