Announcement

Collapse
No announcement yet.

[Guide] Vehicle Cameras

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Guide] Vehicle Cameras

    hello
    i see people strugling with vehicle cameras so heres a guide to help out.
    if your extending from SVehicle use CalcCamera()
    extending from UTVehicle use VehicleCalcCamera()

    starting with using the location of a socket
    Code:
    /** Name of the Bone/Socket to base the camera on */
    	var() name CameraTag;
    
    simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
    {
        local vector SocketLoc;
        local rotator SocketRot;
    
    //get the location and rotation of the socket
        Mesh.GetSocketWorldLocationAndRotation(CameraTag, SocketLoc, SocketRot);
    
            //set the cam location and rotation
    	out_CamLoc = SocketLoc;
    	out_CamRot = SocketRot;
    
    	return true;
    }
    
    defaultproperties
    {
    //change GunViewSocket to whatever your socket is called
    CameraTag=GunViewSocket
    }
    ill do some other cams in the next few posts
    requests?

    #2
    sidescroller cam

    Code:
    simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
    {
    	    // out to the side
    		out_CamLoc = Location;
    
                    //if you want the cam on a 'fixed track' use this line
                    out_CamLoc.Y = 600;
                    //if you want the cam to move in and out with the vehicle use this line instead
    		//out_CamLoc.Y -= 600;
    
    		//up a bit
    		out_CamLoc.Z += 150;
    
            //rotate 90%
    	out_CamRot.Yaw = 16384;
    	out_CamRot.Pitch = 0;
    	out_CamRot.Roll = 0;
    
    	return true;
    }

    Comment


      #3
      chase cam
      Code:
      simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
      {
      	local vector X, Y, Z;
      
          //this makes the camera stay with the vehicle
      	GetActorEyesViewPoint( out_CamLoc, out_CamRot );
      
      	    GetAxes(Rotation,X,Y,Z);
      
      	    // a bit behind
      		out_CamLoc = Location - 400 * X;
      		//up a bit
      		out_CamLoc.Z = Location.Z + 200;
      
          //camera rotation yaw = vehicle rotation yaw
      	out_CamRot.Yaw = Rotation.Yaw;
      	//  look down a bit
      	out_CamRot.Pitch = (-22.0f     *DegToRad) * RadToUnrRot;
      	//delete this line if you want the cam to roll with the vehicle
      	out_CamRot.Roll = 0;
      
      	return true;
      }
      a chase cam with rotational lag.
      Code:
      var float CurrentCamRot, DesiredCamRot;
      var() int myCamOffsetDistance, myCamOffsetHeight;
      var() float CamLag, CamPitch;
      
      simulated function VehicleCalcCamera(float DeltaTime, int SeatIndex, out vector out_CamLoc, out rotator out_CamRot, out vector CamStart, optional bool bPivotOnly)
      {
         local Rotator Rot, PotentialRotation, MaxAngle;
         local vector CamRotX, CamRotY, CamRotZ;
      
              MaxAngle.Yaw = 32768;
      
      	GetActorEyesViewPoint( out_CamLoc, out_CamRot );
      
      	Rot.Roll = 0;
      	Rot.Pitch =  -CamPitch;
      
      	DesiredCamRot = Rotation.Yaw - CurrentCamRot;
      	PotentialRotation.Yaw = DesiredCamRot;
      	ClampRotation(PotentialRotation, Rotation, MaxAngle, MaxAngle);
      	CurrentCamRot += PotentialRotation.Yaw * DeltaTime * CamLag;
      	Rot.Yaw = CurrentCamRot;
      
      	out_CamRot = Rot;
      
      	GetAxes(out_CamRot, CamRotX, CamRotY, CamRotZ);
      
      	out_CamLoc = Location - myCamOffsetDistance * CamRotX;
      	out_CamLoc.Z = Location.Z + myCamOffsetHeight;
      }
      
      DefaultProperties
      {
      myCamOffsetDistance=450
          myCamOffsetHeight=150
          CamLag=0.005
          CamPitch=1000
      }
      a very simple cam with lag that uses a socket location
      Code:
      var() float CamLag;
      
      simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
      {
          local vector SocketLoc;
          local rotator SocketRot;
      
      //get the location and rotation of the socket
              Mesh.GetSocketWorldLocationAndRotation(CameraTag, SocketLoc, SocketRot);
              //set the cam location and rotation
            out_CamLoc = VLerp(out_CamLoc, SocketLoc, CamLag*fDeltaTime); //VLerp to give us lag
          out_CamRot = Rotator(Location - out_CamLoc);   //look at the vehicle
          out_CamRot.Roll = 0;
      }
      
      DefaultProperties
      {
      CamLag=9.0//change this value to give more or less lag
      }

      Comment


        #4
        Hey tegleg,

        Thanks a lot man!

        I have been attaching cameras to the actor and then setting the camera target in kismet. I have a set up which has a console command of "Change Camera" hooked up to a switch with 3 outputs each with their own camera (top, side, chase) and every time you LMB then it changes camera with a binding.

        Would this scripting give you more freedom than hooking up the nodes in kismet? Or does it not really matter? It could also potentially work on multiple vehicles if I did it your way without too much trouble right?

        Cheers

        Pete

        Comment


          #5
          doing the camera in script instead of kismet would mean you dont have to set up the kismet for each map.
          for a change camera function have a look at my big van thing firetruck, it uses cases and an exec function with a key bind.
          it would work on any vehicle without any trouble.

          Comment


            #6
            all in 1 cam

            to assign a key press to change the camera, open up DefaultInput.ini and look for this line
            .Bindings=(Name="B",Command="GBA_ToggleSpeaking")

            directly under add this line, i used X but you can use what you want as long as it isnt taken already
            Code:
            .Bindings=(Name="X",Command="ChangeCam")
            put this in your vehicle script
            Code:
            var() name CameraTag;
            	var int CamType;
            
            exec function ChangeCam()
            {
                CamType++; //add 1 to CamType
            
                if (CamType >= 3)
                {
                 CamType = 0;
                }
            
            }
             //all in 1 cam
            simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
            {
               local vector X, Y, Z;
               local vector SocketLoc;
               local rotator SocketRot;
            
               switch( CamType )
               {
            case 0:  //socket location cam
            	    Mesh.GetSocketWorldLocationAndRotation(CameraTag, SocketLoc, SocketRot);
            
            		out_CamLoc = SocketLoc;
            	    out_CamRot = SocketRot;
            break;
            
            case 1: // sidescroller
                  // out to the side
            		out_CamLoc = Location;
            		out_CamLoc.Y -= 600;
            		//up a bit
            		out_CamLoc.Z += 150;
            
                    //rotate 90%
            	out_CamRot.Yaw = 16384;
            	out_CamRot.Pitch = 0;
            	out_CamRot.Roll = 0;
            break;
            
            case 2:   // chase cam
                  //this makes the camera stay with the vehicle
            	GetActorEyesViewPoint( out_CamLoc, out_CamRot );
            
            	    GetAxes(Rotation,X,Y,Z);
            
            	    // a bit behind
            		out_CamLoc = Location - 400 * X;
            		//up a bit
            		out_CamLoc.Z = Location.Z + 200;
            
                //camera rotation yaw = vehicle rotation yaw
            	out_CamRot.Yaw = Rotation.Yaw;
            	//  look down a bit
            	out_CamRot.Pitch = (-22.0f     *DegToRad) * RadToUnrRot;
            	//delete this line if you want the cam to roll with the vehicle
            	out_CamRot.Roll = 0;
            break;
               }
            
            	return true;
            }
            
            defaultproperties
            {
            //change GunViewSocket to whatever your socket is called
            CameraTag=GunViewSocket
            }

            Comment


              #7
              Brilliant!

              Thank you so much tegleg for your quick response and added code I wont forget to credit your name for the code as well!

              Cheers

              Pete

              Comment


                #8
                You're a lifesaver Tegleg.

                I'm pretty sure my issue was using VehicleCalcCamera() over CalcCamera(). It is working just how I want it now.

                I really appreciate that you took the time to write all this for the community. I would of been lost without it.

                If i wanted to change the FOV of the camera, how would I precede?

                Comment


                  #9
                  out_FOV=whatever

                  Comment


                    #10
                    Teg,

                    Always a help, as usual!

                    Just to be clear, this is on a vehicle by vehicle basis, correct? So I need to insert this code and make alterations to each of my vehicle classes?

                    In addition, a problem I seem to be running into with ANY camera tutorial and vehicles, is the fact that I lose control of the turrets. We'll take the Scorpion as an example, and the issue I'm having is that I can no longer move the turret in any direction. What do you think is causing this?

                    EDIT:
                    So I've gotten all of the camera systems to work (great job Teg!) and realized that when I go to the side scrolling perspective, that the turret faces the direction the camera is facing. How can I make the turret independent of the camera?

                    Comment


                      #11
                      glad you got it working Dvoyles

                      as for an independent aim im not sure.
                      if you want it to just aim forwards either take the line out the seat that refers to the gun bone or take it out the animset.
                      the animset is probably worth messing with, you could even maybe re-assign the gun controlls in there.
                      i dont know tbh, i havnt got round to properly playing with that yet, but i will at some point..

                      Comment


                        #12
                        Ok not a problem. I'll mess around with it a bit over the week and let you know how it goes. If i find anything I'll be sure to let you know in here. Thanks again!

                        Comment


                          #13
                          Hello, tegleg! Very useful help with cameras, BIG THANX!!!! Also i've got question:
                          can we get the camera not fully stick to the car, but make it moves to sides when the car turns and getting back, when it's stopping to turn?
                          (bad english here, sorry)
                          http://www.youtube.com/watch?v=IM1EDbKN05s (0:08, 0:11, 0:13 etc..)
                          here is what i mean
                          and here is what i've got =)
                          http://www.youtube.com/watch?v=g_r0yZu1TfI

                          Waiting for your answer! Hope it's not very hard to create this camera effect =)

                          Comment


                            #14
                            re-volt is ace!, i still got an old comp with that on it

                            you want camera lag, im working on a simple camera like this but its not ready yet.
                            meanwhile, have a look at the scorpion camera, 'CamStart' is the key.

                            Comment


                              #15
                              thanx!!! =) also, if u interested in revolt - http://www.moddb.com/mods/re-volt-rc-stories

                              Comment

                              Working...
                              X