Using Unitys LookAt Function

Slimboy90

New member
Hello there,

im trying to force the play to look at a given point (Vector3) using Unitys lookAt function on the camera object. The player im using is controlled via UFPS.
The code in Update basically looks like this:

lookAt.png

This seems to be working excactly one time, resulting in a change of perspective. As far as i understand, the player should now not be able to look anywhere else. Is it possible that some UFPS component overrides my statement, for example by refocusing the camera?

Boiled down, i want to be able to determine where the player is looking via script. Does anyone know have an idea how one could implement this using UFPS?

Thank you very much in advance :)
 
It's not advisable to forcefully alter the camera/character transform with a custom script like this. I would recommend reading about the CameraController component, in particular the various ViewTypes that are provided. The First Person Transform Look (attach the camera to a specific transform) and Third Person Look At (fix the camera onto a specific transform) ViewTypes may be of interest.

There is also an Aim Assist component which allows the camera and crosshair to lock on to a target: https://opsive.com/support/documentation/ultimate-character-controller/camera/aim-assist/
 
Top