TheLegend
New Member
- Reaction score
- 10
[System] Advanced Third Person Camera
Ever tried to make a third person camera that is almost perfect...well i did that
This camera system can:
-Rotate according to the users wish (includes normal unit rotation)
-Apply the height according to the terrain and unit flying height
-Avoid other objects
-Be switched from one unit to another
What you need:
NewGen World Editor
vJass
Ryoko's terrain pathing test map library (use this one)
Info:
System:
The initialization trigger:
The Unit Swicher:
The turning system is in the map so just copy these. Give me some credit if you use the system.Here is the map:
View attachment UTPC.w3x
Advanced Third Person Camera
by TheLegend aka Codenamed
by TheLegend aka Codenamed
Ever tried to make a third person camera that is almost perfect...well i did that
This camera system can:
-Rotate according to the users wish (includes normal unit rotation)
-Apply the height according to the terrain and unit flying height
-Avoid other objects
-Be switched from one unit to another
What you need:
NewGen World Editor
vJass
Ryoko's terrain pathing test map library (use this one)
Info:
JASS:
//Ultimate Third Person Camera System
//By TheLegend aka Codenamed
//First define some variables:
// camera_main_unit Unit Array - our main unit. This unit is the hero in the game. You can find this useful in RPG games
// camera_target_unit Unit Array - the camera objective. This is the unit wich the camera is locked on
// camera_turn_degree Real Array - the turn rate. Gives the player the ability to rotate the camera
// camera_turnL Boolean Array - Checks if the player wants to turn left
// camera_turnR Boolean Array - Checks if the player wants to turn right
// tempunitgroup Unit Group - A unit group that will prevent leaks
//Copy the triggers to your map. Dont forget the library cause it wont work
//The library isnt mine but the camera system is so dont blaim me
//The Camera Swich Units trigger sets udg_camera_target_unit to the selected unit. If multiple units are selected it searches for the
//udg_camera_main_unit unit and sets it as the main camera unit
//To turn the camera press right and left
//Give me credits if you use the camera please
System:
JASS:
function Trig_Multiplayer_Camera_Actions takes nothing returns nothing
local boolean b //The pathing boolean
local integer i = 1 //The player index counter
local location l = Location(0,0) //A point used to detect height
local real v //The distance of the camera
local real x //Coordinates x,y,z of two points
local real y
local real z
local real x1
local real y1
local real z1
loop
if udg_camera_target_unit<i> != null and (GetWidgetLife(udg_camera_target_unit<i>) > 0.405) then
set v = 25 //We set the minimum distance to 25
set x = GetUnitX(udg_camera_target_unit<i>) //Get the x coordinate of the unit wich has the camera on it
set y = GetUnitY(udg_camera_target_unit<i>) //Get the y coordinate of the unit wich has the camera on it
call MoveLocation(l,x,y) //We move the l point to the units coordinates
set z = GetLocationZ(l) // store the heignt as z
set x1 = x + 64 * Cos((GetUnitFacing(udg_camera_target_unit<i>) + udg_camera_turn_degree<i>) * bj_DEGTORAD)
set y1 = y + 64 * Sin((GetUnitFacing(udg_camera_target_unit<i>) + udg_camera_turn_degree<i>) * bj_DEGTORAD)
call MoveLocation(l,x1,y1)
set z1 = GetLocationZ(l) //We find the point right in front of the unit's camera and get its height
loop //Here begins the main loop for all players
set x1 = x - v * Cos((GetUnitFacing(udg_camera_target_unit<i>) + udg_camera_turn_degree<i>) * bj_DEGTORAD)
set y1 = y - v * Sin((GetUnitFacing(udg_camera_target_unit<i>) + udg_camera_turn_degree<i>) * bj_DEGTORAD)
set b = IsTerrainWalkable(x1, y1) // This part uses the library I implemented to see is the point behind the unit in distance v is pathable
if (b == false) then
set b = IsTerrainDeepWater(x1, y1) // We dont want to avoid water right...
endif
if (GetUnitFlyHeight(udg_camera_target_unit<i>) > 0) then
set b = true
endif // This is just to avoid distance changes if the unit is in the air
if ((b == true) and (v < 450)) then
set v = v + 25
elseif ((b == false) or (v == 450)) then
exitwhen true // This increases the camera distance until the system detects a non-pathable point.
// Max distance can be changed, its the 450 integer
endif
endloop
if GetLocalPlayer() == Player(i - 1) then //Make the system do the folowing stuff only for one player at the time
call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(udg_camera_target_unit<i>) + udg_camera_turn_degree<i>, 0.5) //Set the rotation of the cam to the units+our rotation wish
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, v, 0.2) //Set the distance to v
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 335 + ((z1 - z) * 0.5), 0.32) //This is meant for the player to be able to see the "top of the mountain"
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
call SetCameraField(CAMERA_FIELD_FARZ, 5000, 5) //How far the player will be able to see
call SetCameraTargetController(udg_camera_target_unit<i>, 0, 0, false) //Locks the camera to the unit
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit<i>) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, -0.06)
call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit<i>) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.06) //Height of the camera is adjusted here
endif
endif
exitwhen i == 1 // Change the value here for more players eg: i==9 for nine players
set i = i + 1 //Next player is set
call RemoveLocation(l) //We dont want leaks of points
endloop //Loop ends for one player and starts for another
set l = null //We remove the previous l
endfunction
function InitTrig_Multiplayer_Camera takes nothing returns nothing
set gg_trg_Multiplayer_Camera = CreateTrigger( )
call TriggerRegisterTimerEvent(gg_trg_Multiplayer_Camera,0.06,true) //You can change the time if you want the cam to be faster
call TriggerAddAction( gg_trg_Multiplayer_Camera, function Trig_Multiplayer_Camera_Actions )
endfunction
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
The initialization trigger:
Code:
Initialization
Events
Map initialization
Conditions
Actions
-------- We add each user to the triggers listed below --------
Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
Loop - Actions
Trigger - Add to Camera Swich Units <gen> the event (Player - (Picked player) Selects a unit)
Trigger - Add to TurnLEFT ON <gen> the event (Player - (Picked player) Presses the Left Arrow key)
Trigger - Add to TurnRIGHT ON <gen> the event (Player - (Picked player) Presses the Right Arrow key)
Trigger - Add to TurnLEFT OFF <gen> the event (Player - (Picked player) Releases the Left Arrow key)
Trigger - Add to TurnRIGHT OFF <gen> the event (Player - (Picked player) Releases the Right Arrow key)
-------- We set the main unit and the cam unit --------
Set camera_main_unit[1] = Blood Mage 0004 <gen>
Set camera_target_unit[1] = Blood Mage 0004 <gen>
Code:
Camera Swich Units
Events
Conditions
(Owner of (Triggering unit)) Equal to (==) (Triggering player)
((Triggering unit) is A structure) Equal to (==) False
Actions
-------- we set the camera unit to no unit --------
Set camera_target_unit[(Player number of (Triggering player))] = No unit
-------- to prevent leaks we create a temp unit group --------
Set tempunitgroup = (Units currently selected by (Triggering player))
-------- we search for the main unit in selected units --------
Unit Group - Pick every unit in tempunitgroup and do (Actions)
Loop - Actions
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Picked unit) Equal to (==) camera_main_unit[(Player number of (Owner of (Triggering unit)))]
Then - Actions
Set camera_target_unit[(Player number of (Triggering player))] = (Picked unit)
Else - Actions
Do nothing
-------- we destroy the temp unit group --------
Custom script: call DestroyGroup (udg_tempunitgroup)
-------- if there was no main unit in the selected units we set the camera to any selected unit --------
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
camera_target_unit[(Player number of (Triggering player))] Equal to (==) No unit
Then - Actions
Set camera_target_unit[(Player number of (Triggering player))] = (Triggering unit)
Else - Actions
Do nothing
View attachment UTPC.w3x