Alright first of all create a folder called DSGame then inside that folder create another folder called classes, after that go on defaultengine.ini where you see [UnrealEd.EditorEngine] write +EditPackages=DSGame, now you done that use those codes here i modified them to make it work with UDK newer versions it actually compiles with March 2012 give it a try with May 2012 UDK,
hope i haven't missed any code,
Code:
class DSHUD extends UTHUD;
var texture2D CursorTexture;
var Vector2D MousePosition;
//------------------------------------------------------------
event PostRender()
{
local DSPlayerController PC; //This will hold the player controller
local Vector MouseHitWorldNormal; //Hold the normalized vector of world location to get direction to MouseHitWorldLocation (calculated in HUD, not used)
local Vector MousePosWorldLocation; //Hold deprojected mouse location in 3d world coordinates. (calculated in HUD, not used)
local Vector MousePosWorldNormal; //Hold deprojected mouse location normal. (calculated in HUD, used for camera ray from above)
local vector StartTrace; //Hold calculated start of ray from camera
local Vector EndTrace; //Hold calculated end of ray from camera to ground
local vector RayDir; //Hold the direction for the ray query.
local Actor TraceActor; //If an actor is found under mouse cursor when mouse moves, its going to end up here.
super.PostRender(); //do UTHud.PostRender
PC = DSPlayerController(PlayerOwner); //Set PC as DSPlayerController version of the PlayerOwner
PC.resolution.x = (Canvas.ClipX) ; //find the screen resolution.
PC.resolution.y = (Canvas.ClipY);
if (PC.CameraZoom >1) //if not in first person zoom
{
//this code traces from the camera's location to where your cursor touches something in 3d space so your pawn can aim and shoot at it.
if (PC.CameraZoom == 2)// if third person locked aim, center cursor on screen
// PlayerOwner.GetUIController().SceneClient.SetMousePosition(PC.resolution.x/2,PC.resolution.y/2);
MousePosition = getMouseCoordinates(); //find the cursor coordinates
Canvas.DeProject(MousePosition, MousePosWorldLocation, MousePosWorldNormal); //find the cursor 3d location and direction
RayDir = MousePosWorldNormal;
StartTrace = (PC.PCCameraLoc) + RayDir; //where to start the trace from
EndTrace = StartTrace + RayDir * 5000; //where to end the trace
TraceActor = Trace(PC.MouseHitWorldLocation, MouseHitWorldNormal, EndTrace, StartTrace, true) ; //trace the line, see if it hits anything. store in MouseHitWorldLocation
if (TraceActor == PC.pawn) //if the line hit your pawn
TraceActor = Trace(PC.MouseHitWorldLocation, MouseHitWorldNormal, EndTrace, StartTrace, false) ; //search again, ignoring actors. Don't want to be shooting at yourself
if (PC.MouseHitWorldLocation == vect(0,0,0)) //if the trace doesn't hit anything
PC.MouseHitWorldLocation = EndTrace; // use the end trace location so you'll have somewhere to aim
//self.DrawDebugLine(PC.pawn.location, PC.MouseHitWorldLocation, 1, 255, 1, false); //debug line to use if needed
//PC.PawnEyeLocation = Pawn(PlayerOwner.ViewTarget).Location + Pawn(PlayerOwner.ViewTarget).EyeHeight * vect(0,0,1) ; //Calculate the pawn eye location for debug ray and for checking obstacles on click.
}//if (PC.CameraZoom >1) //if not in first person zoom
} //event PostRender()
//------------------------------------------------------------
function DrawHUD()
{
ConfiguredCrosshairScaling = 0.0; //get rid of the crosshair
super.DrawHUD(); //run UTHud.DrawHud
MousePosition = getMouseCoordinates();//get the mouse position
drawCursor(); //execute Drawcursor() in DSHud
} //function DrawHUD()
//------------------------------------------------------------
function Vector2D getMouseCoordinates() //this function returns the mouse coordinates
{
local IntPoint ScreenPos;
local vector2d MousePos;
// class'UIRoot'.static.GetCursorPosition(ScreenPos.X , ScreenPos.Y);
MousePos.X = float(ScreenPos.X);
MousePos.Y = float(ScreenPos.Y);
return MousePos;
} //function Vector2D getMouseCoordinates()
//------------------------------------------------------------
function drawCursor() //this will draw the cursor where needed
{
Canvas.SetDrawColor(255, 255, 255, 255); //set the draw color
if (DSPlayerController(PlayerOwner).CameraZoom > 2) //if not in a locked aim mode
Canvas.SetPos((MousePosition.X - 16), (MousePosition.Y-16)); //our position will be where the mouse cursor is
else // if in a locked aim mode, draw the cursor at the center of the screen. (our crosshair)
Canvas.SetPos(DSPlayerController(PlayerOwner).resolution.x/2-16,DSPlayerController(PlayerOwner).resolution.y/2-16);
Canvas.DrawTile(CursorTexture, 32 , 32, 126, 0, 64,64); //draw the cursor
}
//------------------------------------------------------------
defaultproperties
{
CursorTexture=Texture2D'UI_HUD.HUD.UTCrossHairs' //set the crosshair image
}
Code:
class DSPlayerController extends UTPlayerController;
//var Vector PawnEyeLocation; //Hold location of pawn eye for rays that query if an obstacle exist to destination to pathfind.
var rotator PCCameraRot; //keeps track of the player controller camera rotation
var vector PCCameraLoc; //keeps track of the player controller camera Location
var float PCCameraOrbit; //this is only the camera orbit that the player wants. Not the actual yaw or location of the camera.
var int CameraZoom; //which camera mode you are in
var Vector MouseHitWorldLocation; //Hold where the ray casted from the mouse in 3d coordinate intersect with world geometry.
var Vector2D resolution; //the screen resolution
var bool bCamRotating; //is the player rotating the camera? (orbiting the player)
//---------------------------------------------------------------------------------------------------
exec function PrevWeapon() //lower camerazoom. to make it easy, we'll just use this to change camera modes. normally you'd make your own function in your PlayerInput Class
{
if (CameraZoom > 1 && !bCamRotating) //if higher than mode 1 and the player is not rotating the camera
{
if (CameraZoom == 2) //in mode 2, about to switch to mode 1
{
Camera('1st'); //tells the camera to switch to first person
PCCameraLoc = Pawn.location ; //set PCCameraLoc to the pawn's position
PCCameraRot = pawn.GetBaseAimRotation() ; //set PCCameraRot to the pawn's Rotation
PCCameraRot.roll = 0; //keep roll at 0
setLocation(PCCameraLoc); //set the Player controller's location to PCCameraLoc
setrotation(PCCameraRot); //set the Player controller's rotation to PCCameraRot
} //if (CameraZoom == 2) //in mode 2, about to switch to mode 1
CameraZoom--; // reduce the camera mode by 1
} //if (CameraZoom > 1
} //exec function PrevWeapon()
//---------------------------------------------------------------------------------------------------
exec function NextWeapon() //raise camerazoom. to make it easy, we'll just use this to change camera modes. normally you'd make your own function in your PlayerInput Class
{
if (CameraZoom < 6 && !bCamRotating)//if lower than camera mode 6 and not rotating the camera
{
Camera('3rd'); //Just in case the camera fell into 1st person somehow, make sure its in 3rd
if (CameraZoom == 1) // in first person. returning to third person locked aim
Camera('3rd');
if (CameraZoom == 2) //in third person locked aim. returning to third person free aim
PCCameraOrbit = (Rotation.Yaw *UnrRotToRad ) * RadToDeg; //updates PCCameraOrbit so that it's behind the player.
CameraZoom++; //raise camerazoom by one
} // if (CameraZoom < 6 && !bCamRotating
}//exec function NextWeapon()
//---------------------------------------------------------------------------------------------------
simulated event GetPlayerViewPoint( out vector POVLocation, out Rotator POVRotation )//tell them where our camera should be
{ //the outs mean these variables are changed and go back out to whatever called the function
//the UT script handles the camera stuff, so we don't use an actual playercamera.ut here. Instead, we simply tell
//the game where we want our playerviewpoint ("camera" location) to be.
local float distance, curdistance; //these variables are explained in UpdateRotation( float DeltaTime )
local vector CamAimLoc,FinalPos;
local rotator CamRotation;
if (CameraZoom > 2) //free aim modes
{
if(Pawn == None) //if pawn does not exist
super.GetPlayerViewPoint(POVLocation, POVRotation);
else //if pawn exists
{
POVLocation = PCCameraLoc; //send back PCCamera information
POVRotation = PCCameraRot;
setrotation(PCCameraRot); //make sure the PlayerController is at the same place as the playerviewpoint
setLocation(PCCameraLoc);
} //else
}// if (CameraZoom > 2)//free aim modes
if (CameraZoom == 1) //first person
{
super.GetPlayerViewPoint( POVLocation, POVRotation );
PCCameraLoc = POVLocation; //run regular UT script and update PCCamera information as the player moves.
PCCameraRot = POVRotation;
}
if (CameraZoom == 2) //third person locked aim
{ //to make this mode work, I had to configure the camera here, instead of update rotation. I wasn't worried about the interpolation.
//these stuff is explained in UpdateRotation( float DeltaTime )
CamRotation = Rotation;
distance = 50;
CamAimLoc.X = 0; //front to back
CamAimLoc.Y = 0; //-aim to the left +aim to the right
CamAimLoc.Z = 60; // up and down
CamAimLoc.X += Pawn.Location.X;
CamAimLoc.Y += Pawn.Location.Y;
CamAimLoc.Z += Pawn.Location.Z;
curdistance = VSize( Location - CamAimLoc);
if(curdistance != distance)
distance = lerp(curdistance, distance, 0.2);
FinalPos = CamAimLoc - Vector(CamRotation) * Distance;
POVLocation = FinalPos; //send back this information
POVRotation = CamRotation;
// setrotation(CamRotation); //doesnt need to be set
setLocation(FinalPos); //make sure the PlayerController is at the same place as the playerviewpoint will be
PCCameraRot = CamRotation; //make sure the PCCamera information is at the same place as the playerviewpoint will be
PCCameraLoc = FinalPos; //I love lamp
} //if (CameraZoom == 2)
} //simulated event GetPlayerViewPoint( out vector POVLocation, out Rotator POVRotation )
//---------------------------------------------------------------------------------------------------
function UpdateRotation( float DeltaTime ) //sets the rotation of the PlayerController and the pawn it is controlling
{
local rotator pcrotation; //these variables are explained in part 2 of this function
local float pitchmultoffset;
local Rotator DeltaRot, ViewRotation, TargetRotation, offsetrotation;
//----part1---------------------------------------------------------------------------
//in part1 of this function, you tell it what rotation you want the camera to have, the target, and the distance, and it finds the right location.
//this script is here instead of in GetPlayerViewPoint because we don't want to interpolate the camera every time something tries to get the player view point.
//CamRotation.Pitch = the desired pitch of the camera. What vertical angle you want to view your target.
//Distance = how far you want to be from your target.
//CamRotation.Yaw = What direction the camera will be facing. 0 is north (12 o'clock). 180 is south (six o'clock).
//CamAimLoc = location the camera is looking at. This is usually an offset from the pawn.
local float distance, curdistance; //curdistance will hold the camera's current distance from the target
local vector CamAimLoc,FinalPos; //FinalPos will be the final calculated camera position
local rotator CamRotation;
//the camera always switches to 1st person on player respawn. this fixes that. You'll get rid of this when your own game dictates respawn conditions.
if (CameraZoom != 1 && !bBehindView) //if camerazoom is not in first person mode and bbehindview is false.
Camera('3rd'); //set camera to 3rd person. bbehindview becomes true.
if (CameraZoom > 2) //if camerazoom is in a 3rd person free aim mode
{
CamRotation.roll = 0;
if(bCamRotating) //if the player has the middle mouse button down to rotate the camera
{
PCCameraOrbit += PlayerInput.aMouseX*0.015; //adjust PCCameraOrbit according to mouse input
if(PCCameraOrbit > 360) PCCameraOrbit -= 360.0f; //fix the value if exceeded 360
if(PCCameraOrbit< 0) PCCameraOrbit += 360.0f;
} //if(bCamRotating)
switch(CameraZoom ) //see descriptions for the variables at the top of the function
{
case 3:
CamRotation.pitch = -20.0f;
CamRotation.yaw = PCCameraOrbit;
distance = 70;
CamAimLoc.X = 0; //set the offsets from the pawn
CamAimLoc.Y = 0;
CamAimLoc.Z = 50;
break;
case 4:
CamRotation.pitch = -30.0f;
CamRotation.yaw = PCCameraOrbit;
distance =300;
CamAimLoc.X = 0;
CamAimLoc.Y = 0;
CamAimLoc.Z = 30;
break;
case 5:
CamRotation.pitch = -45.0f;
CamRotation.yaw = PCCameraOrbit;
distance =500;
CamAimLoc.X = 0;
CamAimLoc.Y = 0; // I like pie
CamAimLoc.Z = 50;
break;
case 6:
CamRotation.pitch = -70.0f;
CamRotation.yaw = PCCameraOrbit;
distance =800;
CamAimLoc.X = 0;
CamAimLoc.Y = 0;
CamAimLoc.Z = 50;
break;
} //switch( PC.CameraZoom )
CamRotation.Pitch = (CamRotation.Pitch *DegToRad) * RadToUnrRot; //convert from degrees to Unreal rotation
CamRotation.Roll = (CamRotation.Roll *DegToRad) * RadToUnrRot;
CamRotation.Yaw = (CamRotation.Yaw *DegToRad) * RadToUnrRot;
CamAimLoc.X += Pawn.Location.X; //add the pawn location to your offsets
CamAimLoc.Y += Pawn.Location.Y;
CamAimLoc.Z += Pawn.Location.Z;
curdistance = VSize( PCCameraLoc - CamAimLoc); //find the distance from the camera to where the camera is aiming
if(curdistance != distance && !bCamRotating) //('erp's) interpolate for smooth transition
distance = lerp(curdistance, distance, 0.2);
if(PCCameraRot != CamRotation && !bCamRotating)
CamRotation = Rlerp (PCCameraRot, CamRotation, 0.05, true);
FinalPos = CamAimLoc - Vector(CamRotation) * Distance; //found the final location for the camera
setrotation(CamRotation); //set the playercontroller
setLocation(FinalPos);
PCCameraRot = CamRotation; //set the pccamera information
PCCameraLoc = FinalPos;
//--------------end part1-----start part2----------------------------------------
//Part 2 of this function aims the pawn at your target. also, it will temporarily aim the playercontroller's
//pitch at the target because UT script uses this to adjust the pawn's aimnode. (aim weapon and arm pitch, but not the pawn's pitch)
TargetRotation = rotator(MouseHitWorldLocation - Pawn.Location); //find the rotation to aim the pawn at the target
pitchmultoffset = 1.5; //adjust the weapon's aim to look more accurate. only a visual effect so you can adjust however you want.
offsetrotation.pitch = -1750; //adjust the weapon's aim to look more accurate. only a visual effect so you can adjust however you want.
offsetrotation.yaw = 0; //adjust the weapon's aim to look more accurate. only a visual effect so you can adjust however you want.
TargetRotation += offsetrotation; //add the offset to your target rotation
TargetRotation.pitch *= pitchmultoffset; //applies the multiplier offset to the pitch
ViewRotation = dspawn(pawn).getbaseaimrotation() ; //gets the pawn's current rotations.
DeltaRot.Pitch = TargetRotation.pitch - ViewRotation.pitch; //find the difference between current and desired rotations.
DeltaRot.Yaw = TargetRotation.Yaw - ViewRotation.Yaw;
if (Pawn!=none)
{
Pawn.SetDesiredRotation(TargetRotation); //self explanitory
}
ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );//this will take deltatime and add deltarot to ViewRotation
pcrotation = ViewRotation; //we don't want to change the playercontroller's yaw, so use a temporary variable...
pcrotation.yaw = Rotation.yaw; //and set the yaw to the playercontroller's current yaw.
SetRotation(pcrotation); // temporarily rotate the playercontroller to this rotation to change the pawn's aim pitch. (not the PAWN'S pitch)
//ViewShake( deltaTime ); //enable this if you like the camera shake effect
ViewRotation.Roll = pawn.Rotation.Roll; //dont change the roll.
if ( Pawn != None )
Pawn.FaceRotation(ViewRotation, deltatime); //aim the pawn at the target. (in our case this will only affect the yaw)
}//if (CameraZoom > 2)
if (CameraZoom < 3)
super.UpdateRotation(DeltaTime ); //if in locked aim mode, run regular UT script.
}//function UpdateRotation( float DeltaTime )
//---------------------------------------------------------------------------------------------------
//in a FPS, your crosshair (playerviewpoint) is always aimed at where you want to shoot. However,
//your WEAPON is almost NEVER aimed correctly. Otherwise, you'd see your pawn's arms constantly
//adjusting the gun up and down to point it at whatever your crosshair is pointed at. The angles
//of you looking at the target and your weapon aiming at the target are different. This is why
//we have to adjust the aim of the actual gunfire itself to hit what you are targeting. You just
//can't tell the difference from that angle. But when you're looking at a pawn from 3rd person, the weapon itself
//will be aimed as accurately as possible (done in updaterotation) just so it will look right.
function Rotator GetAdjustedAimFor(Weapon W, vector StartFireLoc)
{ // This makes our gunfire hit our target location, NOT where the pawn or weapon is aimed.
if (CameraZoom != 1) //if not in first person mode
{
if(Pawn != None)
{
return rotator(MouseHitWorldLocation - startfireloc); // find the rotation from the weapon's barrel to the target.
}
else return Rotation;
} //if (CameraZoom !=1)
else //if not in first person mode, run regular UT script
return super.GetAdjustedAimFor(W,StartFireLoc);
}//function Rotator GetAdjustedAimFor(Weapon W, vector StartFireLoc)
//---------------------------------------------------------------------------------------------------
simulated function PostBeginPlay() //make sure the correct camera types are being used
{
if (CameraZoom == 1)
Camera('1st');
else Camera('3rd');
super.PostBeginPlay();
}
//---------------------------------------------------------------------------------------------------
//moving in a direction will be according to the angle you're looking at it, not the pawn's orientation.
state PlayerWalking {
function PlayerMove( float DeltaTime )
{
local vector X,Y,Z, NewAccel;
local eDoubleClickDir DoubleClickMove;
local rotator OldRotation;
local bool bSaveJump;
if (CameraZoom !=1)
{
if( Pawn == None )
GotoState('Dead');
else
{
GetAxes(Rotation,X,Y,Z); //playercontroller's axis
NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
NewAccel.Z = 0;
NewAccel = Pawn.AccelRate * Normal(NewAccel);
DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
// Update rotation.
OldRotation = Rotation;
UpdateRotation( DeltaTime );
bDoubleJump = false;
if( bPressedJump && Pawn.CannotJumpNow() )
{
bSaveJump = true;
bPressedJump = false;
}
else
{
bSaveJump = false;
}
if( Role < ROLE_Authority ) // then save this move and replicate it
{
ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
}
else
{
ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
}
bPressedJump = bSaveJump;
}
}//if (CameraZoom !=1)
else super.PlayerMove( DeltaTime );
} //function PlayerMove
} //state PlayerWalking {
//---------------------------------------------------------------------------------------------------
DefaultProperties
{
bForceBehindview=false;
bCamRotating = false;
InputClass=class'DSGame.DSPlayerInput'
PCCameraOrbit = 0;
CameraZoom = 1;
PCCameraRot = (Roll = 0,Yaw = 0,Pitch = 0);
PCCameraLoc = (x = 0,y = 0,z = 0);
// JustSwitchedCamera = false;
}
Code:
class DSPlayerInput extends UTPlayerInput Within DSPlayerController;
//you can set this up to execute in your defaultinput.ini . search the forum for instructions on that if you don't know how.
simulated exec function MMCamRotate() //start rotating the camera (Middle Mouse down)
{
bCamRotating = true;
}
simulated exec function UnMMCamRotate() //Stop rotating the camera (Middle Mouse up)
{
bCamRotating = false;
}
Code:
class DSPawn extends UTPawn;
simulated event rotator GetViewRotation()
{
if (DSPlayerController(Instigator.Controller).CameraZoom > 1)
return Rotation; //return the pawn's rotation if in 3rdperson
else return super.GetViewRotation(); //else run the regular UT code
}
//-----------------------------------------
simulated function name GetDefaultCameraMode( PlayerController RequestedBy )
{
if (DSPlayerController(Instigator.Controller).CameraZoom == 1 )
return 'FirstPerson'; //you can't see your penis when you're looking up.
else
return 'ThirdPerson'; //unless you have a mirror.
}
//-----------------------------------------
simulated singular event Rotator GetBaseAimRotation()
{
local vector POVLoc;
local rotator POVRot; //or you're REALLY well equipped.
if( Controller != None && DSPlayerController(Instigator.Controller).CameraZoom == 1 )
{
Controller.GetPlayerViewPoint(POVLoc, POVRot);
return POVRot; //only use the playercontroller's viewpoint if in first person
}
POVRot = Rotation; //otherwise use the pawn's rotation
// If our Pitch is 0, then use RemoveViewPitch
if( POVRot.Pitch == 0 )
{
POVRot.Pitch = RemoteViewPitch << 8; //and also get his aim pitch (not the PAWN'S pitch, which is 0)
}
return POVRot;
}
//-----------------------------------------
simulated function ProcessViewRotation( float DeltaTime, out rotator out_ViewRotation, out Rotator out_DeltaRot )
{
// Add Delta Rotation to viewrotation and send it back
out_ViewRotation += out_DeltaRot;
out_DeltaRot = rot(0,0,0);
if ( PlayerController(Controller) != None && DSPlayerController(Instigator.Controller).CameraZoom == 1 )
{ //only limit the view rotation when you're in first person.
out_ViewRotation = PlayerController(Controller).LimitViewRotation( out_ViewRotation, ViewPitchMin, ViewPitchMax );
}
}
//-----------------------------------------
simulated function WeaponAttachmentChanged()
{
super.WeaponAttachmentChanged();
if(CurrentWeaponAttachment != None)
{
CurrentWeaponAttachment.Mesh.SetOwnerNoSee(False); //make sure the weapon is visible.
}
}
//-----------------------------------------
Code:
class DSGameInfo extends UTGame;
defaultproperties
{
bDelayedStart=false
PlayerControllerClass=class'DSGame.DSPlayerController'
DefaultPawnClass=class'DSGame.DSPawn'
Name="Default__DSGameInfo"
HUDType=class'DSGame.DSHUD' //Link to my HUD
}
Bookmarks