System Third Person Camera View

Sooda

Diversity enchants
Reaction score
318
I have done "system" what allows with two simple custom script to change player camera view and make it follow unit what you want. All camera settings are customizable. This is concept by Blizzard Entertainment what they used in
Azeroth Grand Prix map. The famous racing game with third person camera view.
Now it' s very simple to manipulate with player camera. Supports 12 players.

azerothgrandprixcamerasgr1.jpg


There isn' t README in map itself because of bugs with JNGP and TESH made it unable to save README within map. Thats why I can' t fix that spelling error also (consept should be concept). You have to use this as reference here:

Azeroth Grand Prix Camera System version 1.00
by Sooda (www.thehelper.net)

Credits for concept goes to Blizzard Entertainment. This system is based off of
Azeroth Grand Prix map.


1.0 World Editor Requirements
1.1 How to setup system
1.2 How to use custom functions
1.2.1 function STPC_Blizzard_SetCameraCustomValues
1.2.2 function STPC_Blizzard_ApplyCustomCameraToUnit



1.0 World Editor Requirements

This system needs vJASS parser called JassHelper. You can get it from Jass NewGen Pack:
http://www.wc3campaigns.net/showthread.php?t=90999
or just google/ search from net.

1.1 How to setup system

Create new trigger and name it "STPC Blizzard Custom Camera View" (Without ""
and be careful trigger name is case sensitive. So don' t write
"StPc BlIzZaRd CuStOm CaMeRa ViEw" or "STPC BLIZZARD CUSTOM CAMERA VIEW".).
Convert that newly made trigger to custom text (Edit > Convert To Custom Text).
After that delete everything what you see there and copy paste
"STPC Blizzard Custom Camera View" trigger content into newly made trigger.
Save map twice or how many times you have to do it (So it gets saved correctly)
and start using system.

1.2 There are available two custom functions one is for applaying custom
camera to unit and another is to change settings of custom camera view.


1.2.1 STPC_Blizzard_SetCameraCustomValues
Lets start from second custom function what allows you to set custom camera view:


Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(whichPlayer,cameraTargetDistance,cameraFieldOfView,cameraRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)


STPC_Blizzard_SetCameraCustomValues is name of our functions. All things
what are between () after function name are called arguments. I will explane
what each argument will modify:

whichPlayer - is player whom settings you want to modify. It takes player
variable. If you made variable called "PlayerOne" (without "") then you have
to add prefix "udg_" (without ""). It will look now like this:
"udg_PlayerOne"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,cameraTargetDistance,cameraFieldOfView,cameraRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)

Notice how we replaced whichUnit with our player variable called
"udg_PlayerOne" ?

cameraTargetDistance - is distance from camera source to camera target (object).
Camera source is point where player camera is at time. Camera target is your unit
what will be followed. It takes real variable. If you made variable called
"PlayerOneDistance" then you have to add prefix "udg_" (without ""). It will look
now like this:

"udg_PlayerOneDistance"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,cameraFieldOfView,cameraRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)

cameraFieldOfView - The width that the camera can see. Changing this value
'zooms' the camera in and out (Credits to Darg from www.thehelper.net for that
sentence.).It takes real variable. If you made variable called
"PlayerFieldOfView" then you have to add prefix "udg_" (without ""). It will look
now like this:

"udg_PlayerFieldOfView"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,cameraRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)

cameraRotationVelocity - determines speed how fast will camera turn where
camera target (object/ unit) is facing at that time moment. It takes real
variable. If you made variable called "PlayerRotationVelocity" then you have to
add prefix "udg_" (without ""). Keep in mind that it uses percentages where 1.00
means 100 % and 0.01 means 1 %. That percent is camera target current turning
speed. By default it is 30 % slower than unit current turning speed. What means
it' s 1.30. It will look now like this:

"udg_PlayerRotationVelocity"


and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,udg_PlayerRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)

cameraZOffSet - determines how high from ground will be camera all the time.
Keep in mind that it considers unit height from ground (current flying height of
unit) ground height. It keeps player view always behind or above of camera target
(object). It takes real variable. If you made variable called
"PlayerZOffSet" then you have to add prefix "udg_" (without ""). It will look
now like this:

"udg_PlayerZOffSet"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,udg_PlayerRotationVelocity,udg_PlayerZOffSet,cameraAoA,cameraFarZ,applySettings)

cameraAoA - The angle that the camera is pointing towards the target (Credits
again to Darg). It works with degrees and 360.00 degrees would be behind of
unit while 0.00 would be front of unit. Default is 340.00 degrees what gives
good third person view feeling. It takes real variable. If you made variable
called "PlayerAoA" then you have to add prefix "udg_" (without "").
It will look now like this:

"udg_PlayerAoA"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,udg_PlayerRotationVelocity,udg_PlayerZOffSet,udg_PlayerAoA,cameraFarZ,applySettings)

cameraFarZ - Total distance that the camera can see. Anything past is shown
as sky, or a horizon line (Credits to Darg once again). Though I' m not very
sure about it. Default is 5500.00. It takes real variable. If you made variable
called "PlayerFarZ" then you have to add prefix "udg_" (without "").
It will look now like this:

"udg_PlayerFarZ"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,udg_PlayerRotationVelocity,udg_PlayerZOffSet,udg_PlayerAoA,udg_PlayerFarZ,applySettings)

applySettings - determines are new settings used. You can set it false to
change settings for player camera view but not applying them instantly. It
takes boolean variable. If you made variable called "PlayerApplySettings" then
you have to add prefix "udg_" (without "").
It will look now like this:

"udg_PlayerApplySettings"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_SetCameraCustomValues(udg_PlayerOne,udg_PlayerOneDistance,udg_PlayerFieldOfView,udg_PlayerRotationVelocity,udg_PlayerZOffSet,udg_PlayerAoA,udg_PlayerFarZ,udg_PlayerApplySettings)

Now you are ready to start editing custom camera view settings with this
custom script. Keep in mind that all variables made from Variable Editor will
require "udg_" prefix before their actual name when using in custom scripts.
Though when you are using vJASS made variables they might (or mostly) don' t
use "udg_" prefix. Then make sure variable name what you want to use in
custom script is exactly written like it was declared.
For example if variable name is "sys_cameraTarg" (without "") then use it like
that and don' t add "udg_" prefix because it dosn' t need it.


1.2.2 STPC_Blizzard_ApplyCustomCameraToUnit

This function is much simpler than previous one.

Code:
Custom script:   call STPC_Blizzard_ApplyCustomCameraToUnit(whichUnit,whichPlayer,applyCamera)

STPC_Blizzard_ApplyCustomCameraToUnit is name of our functions. All things
what are between () after function name are called arguments. I will explane
what each argument will modify:

whichUnit - is unit what will be constantly followed by player camera view.
It takes unit variable. If you made variable called "PlayerWhichUnit" then
you have to add prefix "udg_" (without "").
It will look now like this:

"udg_PlayerWhichUnit"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_ApplyCustomCameraToUnit(udg_PlayerWhichUnit,whichPlayer,applyCamera)

whichPlayer -
whichPlayer - is player whom camera view will start to follow unit.
It takes player variable. If you made variable called "PlayerOne" (without "")
then you have to add prefix "udg_" (without ""). It will look now like this:
"udg_PlayerOne"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_ApplyCustomCameraToUnit(udg_PlayerWhichUnit,udg_PlayerOne,applyCamera)

applyCamera - turns on and off unit following by player current camera. If it is
false player current camera will be reset over one second to default Warcraft
camera view. It takes boolean variable. If you made variable
called "PlayerApplyCamera" (without "") then you have to add prefix "udg_"
(without ""). It will look now like this:

"udg_PlayerApplyCamera"

and you can use it like this in custom script:

Code:
Custom script:   call STPC_Blizzard_ApplyCustomCameraToUnit(udg_PlayerWhichUnit,udg_PlayerOne,udg_PlayerApplyCamera)

Now you are ready to start applying custom camera views to players with this
custom script. Keep in mind that all variables made from Variable Editor will
require "udg_" prefix before their actual name when using in custom scripts.
Though when you are using vJASS made variables they might (or mostly) don' t
use "udg_" prefix. Then make sure variable name what you want to use in
custom script is exactly written like it was declared.
For example if variable name is "sys_cameraTarg" (without "") then use it like
that and don' t add "udg_" prefix because it dosn' t need it.

end of README

Actual JASS from map itself:
JASS:
globals
	boolean array STPC_Blizzard_ActivateCamera
	boolean array STPC_Blizzard_UseCustomValues
	
	// Default
	real STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE = 700.
	real STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW = 100.
	real STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY = 1.3 // 1. = 100 %, .01 = 1 %
	real STPC_Blizzard_CAMERA_FIELD_ZOFFSET = 100.
	real STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK = 340.
	real STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE = 300.
	real STPC_Blizzard_CAMERA_FIELD_FARZ = 5500.
	
	// Local player
	real array STPC_Blizzard_CameraFieldTargetDistance
	real array STPC_Blizzard_CameraFieldFieldOfView
	real array STPC_Blizzard_CameraFieldRotationVelocity
	real array STPC_Blizzard_CameraFieldZOffSet
	real array STPC_Blizzard_CameraFieldAngleOfAttack
	real array STPC_Blizzard_CameraFieldAngleOfAttackAlternative
	real array STPC_Blizzard_CameraFieldFarZ
	
	unit array STPC_Blizzard_CameraTarget
	
	integer STPC_Blizzard_InstanceCounter = 0
	
	real STPC_Blizzard_CameraTimerTimeout = .05 // 1. = 1 second
	timer STPC_Blizzard_CameraTimer = CreateTimer()
	
	trigger STPC_Blizzard_PanCameraTrig = CreateTrigger()
	
endglobals

function STPC_Blizzard_SetCameraCustomValues takes player whichPlayer, real cameraTargetDistance, real cameraFieldOfView, real cameraRotationVelocity, real cameraZOffSet, real cameraAoA, real cameraFarZ, boolean applySettings returns nothing
	local integer playerIndex = GetPlayerId(whichPlayer)
	
	set STPC_Blizzard_CameraFieldTargetDistance[playerIndex] = cameraTargetDistance
	set STPC_Blizzard_CameraFieldFieldOfView[playerIndex] = cameraFieldOfView
	set STPC_Blizzard_CameraFieldRotationVelocity[playerIndex] = cameraRotationVelocity
	set STPC_Blizzard_CameraFieldZOffSet[playerIndex] = cameraZOffSet
	set STPC_Blizzard_CameraFieldAngleOfAttack[playerIndex] = cameraAoA
	set STPC_Blizzard_CameraFieldAngleOfAttackAlternative[playerIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
	set STPC_Blizzard_CameraFieldFarZ[playerIndex] = cameraFarZ
	set STPC_Blizzard_UseCustomValues[playerIndex] = applySettings
endfunction

library STPCBlizzardApplyCustomCameraToUnit

function STPC_Blizzard_ApplyCustomCameraToUnit takes unit whichUnit, player whichPlayer, boolean turnCameraOn returns nothing
	local integer playerIndex = GetPlayerId(whichPlayer)
	
	set STPC_Blizzard_ActivateCamera[playerIndex] = turnCameraOn
	
	if (turnCameraOn) then
		set STPC_Blizzard_CameraTarget[playerIndex] = whichUnit
		
		if (STPC_Blizzard_InstanceCounter == 0) then
			set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter + 1
			call TimerStart(STPC_Blizzard_CameraTimer,STPC_Blizzard_CameraTimerTimeout,true,null)
		else
			set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter + 1
		endif
	else
		set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter - 1
		
		if (GetLocalPlayer() == Player(playerIndex)) then
			call ResetToGameCamera(1.)
		endif
		
		if (STPC_Blizzard_InstanceCounter <= 0) then
			set STPC_Blizzard_InstanceCounter = 0
			call PauseTimer(STPC_Blizzard_CameraTimer)
		endif
	endif
endfunction

endlibrary

library STPCBlizzardCustomCamera requires STPCBlizzardApplyCustomCameraToUnit

function STPC_Blizzard_ResetCameraTarget takes nothing returns boolean
	local integer playerIndex = 0
	local unit cameraTarget
	
	local location cameraSourceLoc
	local real cameraSourceZ
	
	local real cameraFieldTargetDistance
	local real cameraFieldFieldOfView
	local real cameraFieldRotationVelocity
	local real cameraFieldRotation
	local real cameraFieldZOffSet
	local real cameraFieldAngleOfAttack
	local real cameraFieldAngleOfAttackAlternative
	local real cameraFieldFarZ
	local real cameraTimerTimeout = STPC_Blizzard_CameraTimerTimeout * 2.
	local real cameraRotationTime
	
	loop
		exitwhen playerIndex > 11
			if (STPC_Blizzard_ActivateCamera[playerIndex]) and (STPC_Blizzard_CameraTarget[playerIndex] != null) then
				set cameraTarget = STPC_Blizzard_CameraTarget[playerIndex]
				
				if (GetLocalPlayer() == Player(playerIndex)) then
					set cameraSourceLoc = GetCameraEyePositionLoc()
				endif
				
				set cameraSourceZ = GetLocationZ(cameraSourceLoc)
				call RemoveLocation(cameraSourceLoc)
				set cameraSourceLoc = null
					
				if (STPC_Blizzard_UseCustomValues[playerIndex]) then
					set cameraFieldTargetDistance = STPC_Blizzard_CameraFieldTargetDistance[playerIndex]
					set cameraFieldFieldOfView = STPC_Blizzard_CameraFieldFieldOfView[playerIndex]
					set cameraFieldRotation = GetUnitFacing(STPC_Blizzard_CameraTarget[playerIndex])
					set cameraFieldRotationVelocity = ( GetUnitTurnSpeed(STPC_Blizzard_CameraTarget[playerIndex]) * STPC_Blizzard_CameraFieldRotationVelocity[playerIndex])
					set cameraFieldZOffSet = (STPC_Blizzard_CameraFieldZOffSet[playerIndex] + GetUnitFlyHeight(STPC_Blizzard_CameraTarget[playerIndex]) + cameraSourceZ)
					set cameraFieldAngleOfAttack = STPC_Blizzard_CameraFieldAngleOfAttack[playerIndex]
					set cameraFieldAngleOfAttackAlternative = STPC_Blizzard_CameraFieldAngleOfAttackAlternative[playerIndex]
					set cameraFieldFarZ = STPC_Blizzard_CameraFieldFarZ[playerIndex]
				else
					set cameraFieldTargetDistance = STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE
					set cameraFieldFieldOfView = STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW
					set cameraFieldRotation = GetUnitFacing(STPC_Blizzard_CameraTarget[playerIndex])
					set cameraFieldRotationVelocity = (GetUnitTurnSpeed(STPC_Blizzard_CameraTarget[playerIndex]) * STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY)
					set cameraFieldZOffSet = (STPC_Blizzard_CAMERA_FIELD_ZOFFSET + GetUnitFlyHeight(STPC_Blizzard_CameraTarget[playerIndex]) + cameraSourceZ)
					set cameraFieldAngleOfAttack = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK
					set cameraFieldAngleOfAttackAlternative = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
					set cameraFieldFarZ = STPC_Blizzard_CAMERA_FIELD_FARZ
				endif
			
				if (GetLocalPlayer() == Player(playerIndex)) then
					call SetCameraTargetController(cameraTarget, 0., 0., true)
				
					if ( GetCameraField(CAMERA_FIELD_TARGET_DISTANCE) != cameraFieldTargetDistance ) then
						call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, cameraFieldTargetDistance, cameraTimerTimeout )
					endif
					
					if ( GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW) != cameraFieldFieldOfView ) then
						call SetCameraField( CAMERA_FIELD_FIELD_OF_VIEW, cameraFieldFieldOfView, cameraTimerTimeout )
					endif
        
					if ( GetCameraField(CAMERA_FIELD_ROTATION) != cameraFieldRotation ) then
						call SetCameraField( CAMERA_FIELD_ROTATION, cameraFieldRotation, cameraFieldRotationVelocity )
					endif
					
					if ( GetCameraField(CAMERA_FIELD_ZOFFSET) != cameraFieldZOffSet ) then
						call SetCameraField( CAMERA_FIELD_ZOFFSET, cameraFieldZOffSet, cameraTimerTimeout )
					endif
					
					if ( GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK) != cameraFieldAngleOfAttack ) then
						call SetCameraField( CAMERA_FIELD_ANGLE_OF_ATTACK, cameraFieldAngleOfAttack, cameraTimerTimeout )
					endif
					
					if ( GetCameraField(CAMERA_FIELD_FARZ) != cameraFieldFarZ ) then
						call SetCameraField( CAMERA_FIELD_FARZ, cameraFieldFarZ, cameraTimerTimeout )
					endif
				endif
			endif
		set playerIndex = playerIndex + 1
	endloop
	
	return false
endfunction

endlibrary
//===========================================================================
function InitTrig_STPC_Blizzard_Custom_Camera_View takes nothing returns nothing
    local integer arrayIndex = 0
	
	loop
		exitwhen arrayIndex > 11
			// Local player
			set STPC_Blizzard_CameraFieldTargetDistance[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE
			set STPC_Blizzard_CameraFieldFieldOfView[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW
			set STPC_Blizzard_CameraFieldRotationVelocity[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY
			set STPC_Blizzard_CameraFieldZOffSet[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ZOFFSET
			set STPC_Blizzard_CameraFieldAngleOfAttack[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK
			set STPC_Blizzard_CameraFieldAngleOfAttackAlternative[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
			set STPC_Blizzard_CameraFieldFarZ[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_FARZ
			set STPC_Blizzard_ActivateCamera[arrayIndex] = false
			set STPC_Blizzard_UseCustomValues[arrayIndex] = false
			set STPC_Blizzard_CameraTarget[arrayIndex] = null
		set arrayIndex = arrayIndex + 1
	endloop
	
	call TriggerRegisterTimerExpireEvent( STPC_Blizzard_PanCameraTrig, STPC_Blizzard_CameraTimer )
    call TriggerAddCondition( STPC_Blizzard_PanCameraTrig, Condition (function STPC_Blizzard_ResetCameraTarget))
endfunction


This should not desync and if I find time and can solve issue with JNGP and TESH so I could add README into map it will be done. I suggest you all to check out test map what shows system in action. It is attached under my post (See attached files). Any comments ?
 

Attachments

  • Azeroth Grand Prix Third Person Camera.w3x
    23.8 KB · Views: 300

Naminator

Coming Back To Life
Reaction score
76
Nice job!. Like the view from the hill in 3rd Person Camera. Very good.

+rep :D
 

X.Terror.X

New Member
Reaction score
10
i call it a very hard advanced trigger because it is so big didnt know it whould be so hard i going to try make 1 to mabye it could work

just something like 0.01 ssec of the game change vision with ofset and decrees to unit looks simple to me

but nice anyway
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Very nice. I might use this in my map ofcourse with credits.

Awesome! :D

I can't see any problems with the code and it seems like it will work fine. Is it alright if I edit it to fit my needs?? I just need to make it more lower as in having a larger AoA (Angle of Attack).

+rep

Rofl... You still have very descriptive map names:
- Azeroth Grand Prix 3rd Person View
- ConvertPhoenixFireTo...System - or w/e it is.

:p
 

Sooda

Diversity enchants
Reaction score
318
> I just need to make it more lower as in having a larger AoA (Angle of Attack).

There is that function:
JASS:
call STPC_Blizzard_SetCameraCustomValues(whichPlayer,cameraTargetDistance,cameraFieldOfView,cameraRotationVelocity,cameraZOffSet,cameraAoA,cameraFarZ,applySettings)

It should let you edit any aspect of camera view. But if it still isn' t enough edit JASS how you like. I don' t mind.
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
Very nice job! What you could slightly improve is the cam behaviour when a unit walks down a slope: here the camera should slightly tilt down a bit, as otherwise the unit is lost from the camera for a moment. Apart from that very well done! The coding looks fine, too. +rep
 

Hero

─║╣ero─
Reaction score
250
Very nice...beautiful...gonna look at code though..see what I can find..lol

+rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top