Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (86,156 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

JiamingSun

Help needed on creating a camera rigidly attached on vehicle

Recommended Posts

JiamingSun

 

 

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!

 

Share this post


Link to post
Share on other sites
LeeC2202

Copy this into a file called VehicleCamTest.cs and place it in your scripts folder. When you are in a vehicle, Shift + K toggles through the camera views.

 

This creates two cameras, one at the front-left corner, one at the front-right corner and shows how you need to update them to keep them in sync with the vehicle rotation.

using System;using System.Windows.Forms;using GTA;using GTA.Math;namespace VehicleCamTest{    public class cVehicleCamTest : Script    {        Ped PlayerPed;        Vehicle PlayerVehicle;        Camera LeftCam;        Camera RightCam;        Vector3 MinDimensions = new Vector3();        Vector3 MaxDimensions = new Vector3();        Vector3 LeftCamPos;        Vector3 RightCamPos;        int CamSelect = 0;        public cVehicleCamTest()        {            this.Tick += onTick;            this.KeyUp += onKeyUp;            Interval = 0;        }        private void onTick(object sender, EventArgs e)        {            // Exits from the loop if the game is loading            if (Game.IsLoading) return;            // A collection of lines that process the player's current state, along with the player's vehicle            if (PlayerPed != Game.Player.Character) PlayerPed = Game.Player.Character;            if (PlayerPed.IsSittingInVehicle() && PlayerVehicle != PlayerPed.CurrentVehicle) SetNewVehicle();            // If we are on-foot, reset the cameras and clear the PlayerVehicle            if (PlayerPed.IsOnFoot && PlayerVehicle != null)            {                CamSelect = 0;                World.RenderingCamera = null;                PlayerVehicle = null;            }            // If we have set a vehicle, update the cameras            if (PlayerVehicle != null) UpdateCams();        }        private void SetNewVehicle()        {            // Get the current player's vehicle            PlayerVehicle = PlayerPed.CurrentVehicle;            // Get the dimensions of the model            PlayerVehicle.Model.GetDimensions(out MinDimensions, out MaxDimensions);            // Set the Left and Right camera positions to the front corners            LeftCamPos = new Vector3(MinDimensions.X, MaxDimensions.Y, 1f);            RightCamPos = new Vector3(MaxDimensions.X, MaxDimensions.Y, 1f);            // Create the cameras if none have been created yet.            if (LeftCam == null)            {                LeftCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);                RightCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);            }            // Attach the cameras            LeftCam.AttachTo(PlayerVehicle, LeftCamPos);            RightCam.AttachTo(PlayerVehicle, RightCamPos);            UI.ShowSubtitle("Set new vehicle and cameras");        }        private void UpdateCams()        {            // Set the camera rotations to match the vehicle            LeftCam.Rotation = PlayerVehicle.Rotation;            RightCam.Rotation = PlayerVehicle.Rotation;        }        private void onKeyUp(object sender, KeyEventArgs e)        {            // If you press a key, toggle through the camera states            if (e.KeyCode == Keys.K && e.Modifiers == Keys.Shift && PlayerVehicle != null)            {                CamSelect = (CamSelect + 1) % 3;                switch (CamSelect)                {                    case 0:                        World.RenderingCamera = null;                        UI.ShowSubtitle("Showing Gameplay Cam View");                        break;                    case 1:                        World.RenderingCamera = LeftCam;                        UI.ShowSubtitle("Showing Left Cam View");                        break;                    case 2:                        World.RenderingCamera = RightCam;                        UI.ShowSubtitle("Showing Right Cam View");                        break;                }            }        }    }}

Share this post


Link to post
Share on other sites
JiamingSun

Wow! Thanks a lot for this detailed solution, you are amazing!

Share this post


Link to post
Share on other sites
LeeC2202

Wow! Thanks a lot for this detailed solution, you are amazing!

 

You're welcome.

 

It is much easier to show something working, than to just describe how it works. I'm a visual guy, so I like visual feedback. :)

Share this post


Link to post
Share on other sites
CamxxCore

 

Copy this into a file called VehicleCamTest.cs and place it in your scripts folder. When you are in a vehicle, Shift + K toggles through the camera views.

 

This creates two cameras, one at the front-left corner, one at the front-right corner and shows how you need to update them to keep them in sync with the vehicle rotation.

using System;using System.Windows.Forms;using GTA;using GTA.Math;namespace VehicleCamTest{    public class cVehicleCamTest : Script    {        Ped PlayerPed;        Vehicle PlayerVehicle;        Camera LeftCam;        Camera RightCam;        Vector3 MinDimensions = new Vector3();        Vector3 MaxDimensions = new Vector3();        Vector3 LeftCamPos;        Vector3 RightCamPos;        int CamSelect = 0;        public cVehicleCamTest()        {            this.Tick += onTick;            this.KeyUp += onKeyUp;            Interval = 0;        }        private void onTick(object sender, EventArgs e)        {            // Exits from the loop if the game is loading            if (Game.IsLoading) return;            // A collection of lines that process the player's current state, along with the player's vehicle            if (PlayerPed != Game.Player.Character) PlayerPed = Game.Player.Character;            if (PlayerPed.IsSittingInVehicle() && PlayerVehicle != PlayerPed.CurrentVehicle) SetNewVehicle();            // If we are on-foot, reset the cameras and clear the PlayerVehicle            if (PlayerPed.IsOnFoot && PlayerVehicle != null)            {                CamSelect = 0;                World.RenderingCamera = null;                PlayerVehicle = null;            }            // If we have set a vehicle, update the cameras            if (PlayerVehicle != null) UpdateCams();        }        private void SetNewVehicle()        {            // Get the current player's vehicle            PlayerVehicle = PlayerPed.CurrentVehicle;            // Get the dimensions of the model            PlayerVehicle.Model.GetDimensions(out MinDimensions, out MaxDimensions);            // Set the Left and Right camera positions to the front corners            LeftCamPos = new Vector3(MinDimensions.X, MaxDimensions.Y, 1f);            RightCamPos = new Vector3(MaxDimensions.X, MaxDimensions.Y, 1f);            // Create the cameras if none have been created yet.            if (LeftCam == null)            {                LeftCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);                RightCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);            }            // Attach the cameras            LeftCam.AttachTo(PlayerVehicle, LeftCamPos);            RightCam.AttachTo(PlayerVehicle, RightCamPos);            UI.ShowSubtitle("Set new vehicle and cameras");        }        private void UpdateCams()        {            // Set the camera rotations to match the vehicle            LeftCam.Rotation = PlayerVehicle.Rotation;            RightCam.Rotation = PlayerVehicle.Rotation;        }        private void onKeyUp(object sender, KeyEventArgs e)        {            // If you press a key, toggle through the camera states            if (e.KeyCode == Keys.K && e.Modifiers == Keys.Shift && PlayerVehicle != null)            {                CamSelect = (CamSelect + 1) % 3;                switch (CamSelect)                {                    case 0:                        World.RenderingCamera = null;                        UI.ShowSubtitle("Showing Gameplay Cam View");                        break;                    case 1:                        World.RenderingCamera = LeftCam;                        UI.ShowSubtitle("Showing Left Cam View");                        break;                    case 2:                        World.RenderingCamera = RightCam;                        UI.ShowSubtitle("Showing Right Cam View");                        break;                }            }        }    }}

 

Just to add to this answer, you could probably use the camera.PointAt() overload that takes an entity and offset, instead of setting the rotation each tick. Can't really say if its a better solution performance wise, but you do avoid that extra frame call.

Share this post


Link to post
Share on other sites
LeeC2202

Both methods do work, however when you set a camera into PointAt mode, it has to calculate the relative offset each update to know where it has to point at, which probably involves rotational computations. Simply copying a property is possibly less cpu intensive, even though it requires an extra call.

 

It's another of those situations where there are several solutions and you just have to pick one. I suppose I swing more towards this method, because I am usually doing much more with a camera in an update function.

 

@JiamingSun In case you are wondering what the other method involves. Under where it says "// Attach the cameras", make it look like this.

// Attach the camerasLeftCam.AttachTo(PlayerVehicle, LeftCamPos);RightCam.AttachTo(PlayerVehicle, RightCamPos);LeftCam.PointAt(PlayerVehicle, LeftCamPos + new Vector3(0, 1, 0));RightCam.PointAt(PlayerVehicle, RightCamPos + new Vector3(0, 1, 0));

And then add // to the start of this line:

//if (PlayerVehicle != null) UpdateCams();

That makes the cameras look at a point directly ahead of them.

Edited by LeeC2202

Share this post


Link to post
Share on other sites
JiamingSun
Posted (edited)

Hi @LeeC2202 @CamxxCore, thanks for your additional information. I came back on this project recently and have met some other problems with both the two methods mentioned above. It would be nice if you can help me to figure this out.

Here is my modified implementation, please ignore the comments for debugging..

 public class cVehicleCamStereo    //public class cVehicleCam : Script    {        Ped PlayerPed;        Vehicle PlayerVehicle;        public Camera LeftCam;        public Camera RightCam;        Vector3 MinDimensions = new Vector3();        Vector3 MaxDimensions = new Vector3();        Vector3 LeftCamPos;        Vector3 RightCamPos;        public int CamSelect = 0;        public cVehicleCamStereo()        {            // this.Tick += onTick;            // this.KeyDown += onKeyDown;            // Interval = 0;        }        public void SwitchTo(int camId)        {            switch (camId)            {                case 0:                    World.RenderingCamera = LeftCam;                    //UI.ShowSubtitle("Showing Left Cam View");                    break;                case 1:                    World.RenderingCamera = RightCam;                    //UI.ShowSubtitle("Showing Right Cam View");                    break;            }        }        public void onTick(object sender, EventArgs e)        {            // Exits from the loop if the game is loading            if (Game.IsLoading) return;            // A collection of lines that process the player's current state, along with the player's vehicle            if (PlayerPed != Game.Player.Character) PlayerPed = Game.Player.Character;            if (PlayerPed.IsSittingInVehicle() && PlayerVehicle != PlayerPed.CurrentVehicle) SetNewVehicle();            // If we are on-foot, reset the cameras and clear the PlayerVehicle            if (PlayerPed.IsOnFoot && PlayerVehicle != null)            {                CamSelect = 0;                World.RenderingCamera = null;                PlayerVehicle = null;            }            // If we have set a vehicle, update the cameras            if (PlayerVehicle != null)            {                //UpdateCamRot();                // Debug camera position                var offset = LeftCam.GetOffsetInWorldCoords(new Vector3 (0, 1f, 0));                //Function.Call(Hash.POINT_CAM_AT_COORD, LeftCam.Handle, offset.X, offset.Y, offset.Z);                World.DrawMarker(MarkerType.Number0, LeftCam.Position, new Vector3(0, 1f, 0), LeftCam.Rotation, new Vector3(0.2f, 0.2f, 0.2f), System.Drawing.Color.Cyan);                World.DrawMarker(MarkerType.Number1, RightCam.Position, new Vector3(0, 1f, 0), RightCam.Rotation, new Vector3(0.2f, 0.2f, 0.2f), System.Drawing.Color.Cyan);            }        }        private void SetNewVehicle()        {            // Get the current player's vehicle            PlayerVehicle = PlayerPed.CurrentVehicle;            // Get the dimensions of the model            PlayerVehicle.Model.GetDimensions(out MinDimensions, out MaxDimensions);            // Set the Left and Right camera positions to the front corners            float baseLine = 1;            float LeftCamX = (MinDimensions.X + MaxDimensions.X) / 2 - baseLine / 2 ;            float RightCamX = (MinDimensions.X + MaxDimensions.X) / 2 + baseLine / 2;            //LeftCamPos = new Vector3(LeftCamX, MaxDimensions.Y / 3, MaxDimensions.Z);            //RightCamPos = new Vector3(RightCamX, MaxDimensions.Y / 3, MaxDimensions.Z);            LeftCamPos = new Vector3(LeftCamX, 0, MaxDimensions.Z);            RightCamPos = new Vector3(RightCamX, 0, MaxDimensions.Z);            // Create the cameras if none have been created yet.            if (LeftCam == null)            {                LeftCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);                RightCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);                //LeftCam.DepthOfFieldStrength = 0;                // Something wrong with the DOF of cameras when using PointAt(), let's take this as a feature for now..                //Function.Call(Hash.SET_CAM_DOF_STRENGTH, LeftCam, (float)500);            }            // Attach the cameras            LeftCam.AttachTo(PlayerVehicle, LeftCamPos);            RightCam.AttachTo(PlayerVehicle, RightCamPos);            LeftCam.PointAt(PlayerVehicle, LeftCamPos + new Vector3(0, 1, 0));            RightCam.PointAt(PlayerVehicle, RightCamPos + new Vector3(0, 1, 0));            //UI.Notify(Function.Call<float>(Hash.GET_CAM_FAR_DOF, LeftCam).ToString());            UI.ShowSubtitle("Set new vehicle and cameras");        }        private void UpdateCamRot()        {            // Set the camera rotations to match the vehicle            LeftCam.Rotation = PlayerVehicle.Rotation;            RightCam.Rotation = PlayerVehicle.Rotation;        }        private void UpdateCamSelect()        {            switch (CamSelect)            {                case 0:                    World.RenderingCamera = null;#if DEBUG                        UI.ShowSubtitle("Showing Gameplay Cam View");#endif                    break;                case 1:                    World.RenderingCamera = LeftCam;#if DEBUG                        UI.ShowSubtitle("Showing Left Cam View");#endif                    break;                case 2:                    World.RenderingCamera = RightCam;#if DEBUG                        UI.ShowSubtitle("Showing Right Cam View");#endif                    break;            }        }        public void ReInit()        {            LeftCam.Destroy();            RightCam.Destroy();            SetNewVehicle();        }        public void onKeyDown(object sender, KeyEventArgs e)        {            // If you press a key, toggle through the camera states            if (e.KeyCode == Keys.S && e.Modifiers == Keys.Shift && PlayerVehicle != null)            {                CamSelect = (CamSelect + 1) % 3;                switch (CamSelect)                {                    case 0:                        World.RenderingCamera = null;#if DEBUG                        UI.ShowSubtitle("Showing Gameplay Cam View");#endif                        break;                    case 1:                        World.RenderingCamera = LeftCam;#if DEBUG                        UI.ShowSubtitle("Showing Left Cam View");#endif                        break;                    case 2:                        World.RenderingCamera = RightCam;#if DEBUG                        UI.ShowSubtitle("Showing Right Cam View");#endif                        break;                }            }        }    } 

Previously I went with the “setting rotation” method, where everything worked perfectly when switching between cameras with “Shift + K”(in my implementation Shift + S). But when I tried to call “SwitchTo()” method outside this class in the main script, the RenderingCamera did switch but it’s not rotating with vehicle anymore for unknown reason. And this doesn’t make sense to me since the World.RenderingCamera did changed but UpdateCamRot() stopped working.

 

 

So I tried with the “PointAt” method as my current implementation shows, this time the camera does switch after “SwitchTo()” invoked but there’s another issue, the image looks very blurred(refer to https://ibb.co/nJV0sS )compares to the GamePlayCamera. I tried tweaking with some game settings and native functions on Depth of Field(DOF) but nothing helps. I noticed that when I set the position of camera(LeftCamPos) a little bit forward the blurring effect goes away but I didn’t figure out why. For some other reason the cameras must sit on the top of the vehicle so I can’t put them far away.

Edited by JiamingSun

Share this post


Link to post
Share on other sites
LeeC2202

 

 

But when I tried to call “SwitchTo()” method outside this class in the main script,

I don't understand what you mean by that. This example is a main script, it's not just a class. This class inherits from Script, so it will run as a script. So unless you are calling the SetNewVehicle() function to update the camera positions and everything, then it won't work.

 

If you have these functions as a standalone class, then you're going to have to pass parameters to them, so that they can update things like vehicle dimensions etc... This line in particular is the one that checks for the player vehicle being changed and calls the SetNewVehicle() function.

if (PlayerPed.IsSittingInVehicle() && PlayerVehicle != PlayerPed.CurrentVehicle) SetNewVehicle();

You're going to have to explain a bit more about how you have your project set up, what your main class is doing, how you have included this class file into it etc...

 

The problem you have experienced with PointAt() is the other reason I don't use it for things like this. It's designed to "point at" something and it uses that something to determine the focal point and depth of field for the camera. I use it in my cinematic camera mod because the camera is always pointing at the player. But if the target entity isn't what you want to focus on, then you have to be very careful what you are doing with the camera.

Share this post


Link to post
Share on other sites
JiamingSun
Posted (edited)

I'm sorry, I should make it clearer.
Yes I'm taking cVehicleCamStereo as a stand-alone class in a separate file, an instance of this class is created in the script I'm writing(a class that inherits Scripts, let's call it A script) and I'm calling the member function SwitchTo() of the stereocam instance within this class. stereocam.onTick() is added into the onTick function in the A script and on each tick what in stereocam.onTick() is called, which will make sure that SetNewVehicle() will be called if the conditions are matched.

The problem I'm currently facing is that although calling SwithTo() will change the rendering camera, the rotation of the camera is not updating with the attached vehicle rotation, and this should not be happening because on each tick UpdateCamRot() should be called.
Hope I have made it clear, a great thanks for your time and patience!

Edited by JiamingSun

Share this post


Link to post
Share on other sites
LeeC2202
Posted (edited)

But that's what I mean... you can't just take a class that runs as a script, turn it into a normal class and then just call one function from it. Everything the original script did, like monitoring the vehicle being changed, updating vehicle limits, setting variables etc... that all has to be done in the calling class.

 

Or you have to turn this into a normal class and then call this class's onTick function from the main script.

 

I have just taken this code, turned it back into a script and it works... because everything is being called as it needs to be. If you intend to use this as is, then I would suggest changing... I was going to suggest a couple of changes but as I said after my first post, it's easier to simply demonstrate something that works.

 

So if we have this main class:

using System;using System.Windows.Forms;using GTA;namespace StereoCameras{    public class cStereoCameras : Script    {        private cVehicleCamStereo StereoCam;        public cStereoCameras()        {            Tick += onTick;            KeyUp += onKeyUp;            Aborted += CStereoCameras_Aborted;            Interval = 0;            Initialise();        }        private void Initialise()        {            StereoCam = new cVehicleCamStereo();        }        private void onTick(object sender, EventArgs e)        {            // Exits from the loop if the game is loading            if (Game.IsLoading) return;            StereoCam.Update();        }        private void onKeyUp(object sender, KeyEventArgs e)        {            switch (e.KeyCode)            {                case Keys.NumPad1:                    StereoCam.SwitchTo(0);                    break;                case Keys.NumPad3:                    StereoCam.SwitchTo(1);                    break;                case Keys.NumPad2:                    StereoCam.SwitchTo(2);                    break;            }        }        private void CStereoCameras_Aborted(object sender, EventArgs e)        {            World.RenderingCamera = null;        }    }}

and this as your cVehicleCamStereo class

using GTA;using GTA.Math;namespace StereoCameras{    public class cVehicleCamStereo    {        Ped PlayerPed;        Vehicle PlayerVehicle;        public Camera LeftCam;        public Camera RightCam;        Vector3 MinDimensions = new Vector3();        Vector3 MaxDimensions = new Vector3();        Vector3 LeftCamPos;        Vector3 RightCamPos;        public cVehicleCamStereo()        {        }        public void SwitchTo(int camId)        {            switch (camId)            {                case 0:                    World.RenderingCamera = LeftCam;                    break;                case 1:                    World.RenderingCamera = RightCam;                    break;                case 2:                    World.RenderingCamera = null;                    break;            }        }        public void Update()        {            // A collection of lines that process the player's current state, along with the player's vehicle            if (PlayerPed != Game.Player.Character) PlayerPed = Game.Player.Character;            if (PlayerPed.IsSittingInVehicle() && PlayerVehicle != PlayerPed.CurrentVehicle) SetNewVehicle();            // If we are on-foot, reset the cameras and clear the PlayerVehicle            if (PlayerPed.IsOnFoot && PlayerVehicle != null)            {                World.RenderingCamera = null;                PlayerVehicle = null;            }            // If we have set a vehicle, update the cameras            if (PlayerVehicle != null)            {                UpdateCamRot();                World.DrawMarker(MarkerType.Number0, LeftCam.Position, new Vector3(0, 1f, 0), LeftCam.Rotation, new Vector3(0.2f, 0.2f, 0.2f), System.Drawing.Color.Cyan);                World.DrawMarker(MarkerType.Number1, RightCam.Position, new Vector3(0, 1f, 0), RightCam.Rotation, new Vector3(0.2f, 0.2f, 0.2f), System.Drawing.Color.Cyan);            }        }        private void SetNewVehicle()        {            // Get the current player's vehicle            PlayerVehicle = PlayerPed.CurrentVehicle;            // Get the dimensions of the model            PlayerVehicle.Model.GetDimensions(out MinDimensions, out MaxDimensions);            // Set the Left and Right camera positions to the front corners            float baseLine = 1;            float LeftCamX = (MinDimensions.X + MaxDimensions.X) / 2 - baseLine / 2;            float RightCamX = (MinDimensions.X + MaxDimensions.X) / 2 + baseLine / 2;            LeftCamPos = new Vector3(LeftCamX, 0, MaxDimensions.Z);            RightCamPos = new Vector3(RightCamX, 0, MaxDimensions.Z);            // Create the cameras if none have been created yet.            if (LeftCam == null)            {                LeftCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);                RightCam = World.CreateCamera(Vector3.Zero, PlayerVehicle.Rotation, 50f);            }            // Attach the cameras            LeftCam.AttachTo(PlayerVehicle, LeftCamPos);            RightCam.AttachTo(PlayerVehicle, RightCamPos);            UI.ShowSubtitle("Set new vehicle and cameras");        }        private void UpdateCamRot()        {            // Set the camera rotations to match the vehicle            LeftCam.Rotation = PlayerVehicle.Rotation;            RightCam.Rotation = PlayerVehicle.Rotation;        }        public void ReInit()        {            LeftCam.Destroy();            RightCam.Destroy();            SetNewVehicle();        }    }}

When you get into a vehicle, NumPad 1 for left camera, NumPad 3 for right camera and NumPad 2 for gameplay camera. That should get you on the right track.

 

Please note, I have removed the comments just so it's less text, nothing is really that different from what you already have, so it should be fairly clear what each part is doing. I also removed the PointAt and reinstated the UpdateCamRot() function, which gets rid of the blurry image.

Edited by LeeC2202

Share this post


Link to post
Share on other sites
JiamingSun

@LeeC2202 Thanks again for your very detailed help!
I've figured out what my issue is with the "camera not rotating" problem, it turns out to be a mistake in programming, I called .SwitchTo() in a for loop which blocked the script runnning so that onTick() is not called during switching between cameras. I came up with another method by checking camera status on each tick and switch when necessary. This time everything works perfectly.
Thanks a lot! I'll opensource this mod when everything is finished.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.