Log in to reply

Help needed on creating a camera rigidly attached on vehicle

  • Hi there, I'm working on a mod with a need of attaching a stereo camera in front of the vehicle(the direction and position of the camera is fixed with the vehicle, like one of the 'v' camera view in the game), but I can only fix its position with camera.AttachTo(), the direction is fixed to a direction in the world coordinate, not the vehicle coordinate. This is the code I'm using(ScriptHookVdotNet):

        public StereoCamera(Entity e)
            leftCam = World.CreateCamera(GameplayCamera.Position, GameplayCamera.Direction, GameplayCamera.FieldOfView);
            rightCam = World.CreateCamera(GameplayCamera.Position, GameplayCamera.Direction, GameplayCamera.FieldOfView);
            // leftCam.PointAt(e.Rotation);   // I tried this but not working as expected.
            leftCam.AttachTo(e, new Vector3(0, 1, 1));
            rightCam.AttachTo(e, new Vector3(0, 0, 1));

    How do I create a camera with its direction fixed with the vehicle? Do I need to update the camera direction with a custom Update() function? Is there any example for this update function..
    Any help is greatly appreciated!

  • You can use the camera.PointAt function. IIRC there is an overload that allows you to point at a specific bone on the vehicle. You could also just use the overload that allows you to provide an offset.

  • Thanks for your reply!
    The problem is resolved by adding a Update() function into onTick().

        private void UpdateCams()
            // Set the camera rotations to match the vehicle
            LeftCam.Rotation = PlayerVehicle.Rotation;
            RightCam.Rotation = PlayerVehicle.Rotation;

    Credit to LeeC2202.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.