I’m trying to figure out what I need to get camera relative movement that makes sense in regards to my use-case. I have this player object that is pulled and rotated towards a small planet. This works with some movement code I had but now that I’m trying to make this work with a non-child cinemachine camera. I tried to use CameraUp as a way to influence the movement but it didn’t work out and the player object just moves in odd directions when I start moving the player around the planet. It’s mostly good at the top of the planet but once I go to the bottom, things get really thrown off. I think it’s because the camera’s vectors are no longer in agreement with this camera relative movement so camera.forward and camera.right will no longer work. What should I try next? Thanks.
void ApplyEngineForce()
{
// Apply a force forward if any kind of stick input is happening
Vector3 cameraForward = cam.transform.forward;
Vector3 cameraRight = cam.transform.right;
Vector3 cameraUp = cam.transform.up;
Vector3 camRelativeVerticalMovement = input.y * cameraForward; // TODO: Should we be using cam when on a planet?
Vector3 camRelativeHorizontalMovement = input.x * cameraRight;
if (rb.velocity.magnitude > maxSpeed)
{
return;
}
if (input == Vector2.zero)
{
return;
}
else
{
if (GetComponent().gravityOrbit != null)
{
if (!relativeMovement)
{
// Not camera friendly (But works when camera is fixed to it and my ship starts where it does
var simpleMoveDirection = new Vector3(input.x, 0, input.y).normalized;
rb.AddForce(transform.TransformDirection(simpleMoveDirection) * accelerationFactor);
}
else
{
// Camera friendly
Vector3 camRelativeMovement = (camRelativeHorizontalMovement + camRelativeVerticalMovement).normalized;
//Vector3 camRelativeMovement = (camRelativeHorizontalMovement + camRelativeVerticalMovement).normalized; //+ (cameraUp * camUpInfluence)).normalized;
Third person cam-around-world stuff can be tricky simply because what do you consider truly “up.”
You still need the three things: camera position, camera look point and what you consider up.
It often comes down to just developing usable heuristics for getting those three things.
It may be helpful to see how a complete tutorial does it for terrestrial things walking around on a sphere, such as Sebastian Lague’s awesome tutorial series on it.
I just left my planetary flight controller camera as first-person:
Are you referring to this video? Also would it be possible in any way to have a camera thats a child of a player object still work within the state driven cameras on Cinemachine. That is really what prompted this whole change in the first place. My script works when the camera is a child but it wont work with the rest of the game which changes camera for specific reasons/states. I know that’s out of scope with this question but it could be another way to get around this and honestly might just be better from a player experience.
I don’t have time to watch it yet but just skimming through the end product, if its first person, that controls the direction you go. the camera is autonomous in my case and the camera is controllable in this example, I would assume that this could be adapted to work with the free cam. it’s just that he’s able to control his camera and i don’t but my movement is still relative to that camera.
So I watched the video. I think it really does make me consider a little bit of my own design. First of all, I figured out that I can make my Cinemachine camera look at the player and follow the player in essentially the same way as a child camera would have. However, now I’m sorta fixated on this new issue which has to do with settings the rotation of my object around the planet. In the vid above, he used a mouse rotation but for some reason, I’m running into a problem where my rotation isn’t playing nice with the gravity mechanism. My game is a little different than a FPS so moving the character has to happen based on the arrow key/controller input. if I replace model in my code with the object the script is attached to, rotations go crazy. This also messes with my camera since now the player is rotating and the following done by cinemachine will misbehave. It doesnt seem right to have the child object containing the model be responsible for rotating but maybe that’s what I have to do for my use-case. Unless is there a way to make sure my rotation via the input I use can work with the gravity rotation?