JanCraymer / FS22_AdjustableCamera

Adjustable Camera Mod for Farming Simulator 22
https://www.twitch.tv/cptcray
16 stars 2 forks source link

Not working on most cameras that track a moving target #6

Open OlSom opened 5 months ago

OlSom commented 5 months ago

I have spent a few hours looking at the VehicleCamera code, different mod vehicles and the code of AdjustableCamera, and I can't figure out why it won't work on most cameras that follow a crane movement such as the MAN TGX 26.640. It does work with all three platinum DLC vehilces that have the crane following camera (Pm Trac, Pm Felix, K 300R).

Have you looked into this? Is it something on the vehicle side or could it possibly worked around in the mod? I often find it would be useful to move a camera around when operating a crane from the cab and one of the pillars blocks the view.

JanCraymer commented 5 months ago

Hello OlSom,

I'm not quite sure if I understood the problem already. Is the MAN a mod? If yes, can you link it please, so I can take a look at it? I also don't own the platinum DLC so I cannot test with the machines you named. If you know of any other mods that have the problem, please link them.

My best guess is that the cameras are not defined as indoorCamera which the script is specifically looking for. If you feel comfortable to fiddle with the code, you might alter/remove the if conditions and try if that helps.

OlSom commented 5 months ago

image

This is the one I meant, in the forestry category. Might be a bad example since the crane camera an outdoor one. But even with the indoor condition removed, the crane cannot be adjusted. Interestingly, the 3rd person camera will be adjustable too.

I'm not sure if there are base game versions with indoor tracking cameras, but there are plenty of mods, for example this Rottne F20D which adds a second camera in the cab that tracks follows the crane.

So far the 3 machines from the platinum DLC are the only ones I found where a crane tracking camera can be adjusted, but sadly the DLC vehicles XMLs aren't available.

OlSom commented 5 months ago

An interesting thing I just noticed, it also doesn't work with the normal interior camera of the Valtra 8750 which seems like it should be like any other interior camera.

JanCraymer commented 5 months ago

First of all, the Valtra 8750 works for me. Did you try without any other mods just to rule out any mod conflicts?

Then I went through the MAN TGX with the debugger but I did not find anything useful yet. I can see that the variables are updated as they should, but that does not reflect on the camera position which is strange. Maybe there is some special game function that pins the camera to the crane position or so.

I'll keep looking when I got more time. I still think that it might be fixable somehow.

OlSom commented 5 months ago

I figured it out!

The reason it doesn't work is the following line in the VehicleCamera:update function: image

The zoom value is calculated based on the cameras distance to it's parent node: image

But crane following cameras usually have a parent transform group in the exact same position as the camera, to avoid the camera moving while it's rotating image

This results in an zoom value that's basically zero image

Which means the adjustment steps have such a tiny effect that it's not noticeable.

This seems to be a working fix for it but I have only tested on a couple of vehicles so there might be some side effects to it: image image

OlSom commented 5 months ago

Oh and regarding the other vehicles. The Valtra 8750 didn't work for me even without other mods, and it's for the same reason as the moving cameras, it's indoor camera is in the same position as it's parent node, so it has a close to zero zoom value. I really don't understand how it could work for you.

The Platinum expansion vehicles I mentioned in my first comment aren't actually an exceptions to this, I just misunderstood how they work. It's not the camera following the crane, but rather the seat, so the camera has a reasonable distance to it's parent node like other normal indoor cameras.

JanCraymer commented 5 months ago

Great, thank you for investigating, very helpful! :-)

I've added your fix along with some adjustment to the repo. It still needs some cleanup since the current design did not expect multiple cameras to be changed per vehicle. It can get messy if two cameras were changed and then you hit the reset button.

Overall I wish there was a better way to implement the camera movement to make it more consistent but I think that is not possible without overiding the whole VehicleCamera:update() function which I would not really want to do because that could break other mods.

About the Valtra, yes, my bad. I was testing with headtracking enabled which changes the behavior. Without headtracking, same problem.

Another thing with the MAN TGX I noticed is, that the adjustment of the crane camera is inverted. Maybe the camera rotation is the reason for that, I'm not sure yet.

OlSom commented 5 months ago

Glad I could help :)

I think resetting multiple cameras isn't an issue, you basically solved it already with the new "changedByAdjustableCameraMod" boolean, you just need to save the original X Y Z and zoom into the camera instead of the spec. Be aware that the origTransX is already used by the game, so something like this:

image