Ultimate Third Person Camera

TheLegend

New Member
Reaction score
10
[System] Advanced Third Person Camera

Advanced Third Person Camera
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>) &gt; 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&#039;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>) &gt; 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 &lt; 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 &quot;top of the mountain&quot;
            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>
The Unit Swicher:
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
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
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
This hardly is the ultimate system. there are many reasons:
1). you should change those variable names, in most maps they are probably already taken, not to say they are confusing.
2). the triggers leak memory
3). many functions do not make any sense:
Code:
Set player_camera[(Player number of (Triggering player))] = No unit
Set player_camera[(Player number of (Triggering player))] = (Picked unit)
(the first line is completely useless
Code:
Do nothing
(does what it is called after)

besides these things which are rather easy to see you should also keep in mind, that the arrow keys are slow in multiplayer. movement systems using these are annoying instead of funny. real alternatives are rare though.


and i would never advice you to call anything "ultimative", thats the first negative thing one catchs when reading this thread.
 

TheLegend

New Member
Reaction score
10
I called it Ultimate cause i didnt come up with a better idea xD. Ok, about your 3rd line. I set the player cam to no unit to avoid the bug when you can see the units he loops (You actualy see it set the cam to each unit so it jumps arround a bit)
-I know the triggers leak (unit groups and stuff like that) but the jass code doesnt (the triggers were made half an hour ago when I was in a rush)
-wich variables, the globals or ordinary. The player variable is you in an RPG map so thats why its named (Ill rename it to main_camera_unit and current_camera_unit)
-the Do nothing is just a habit I have so its no big deal. Where do the triggers leak again?
EDIT

I fixed the leaks and the variable names. Hope you like it :)
 

TheLegend

New Member
Reaction score
10
I fixed all the leaks and changed the variable named. The camera target switcher works nice and the turning system is now debugged (the spin bug is now gone). Give me some credits if you use this system
 

Curo

Why am I still playing this game...?
Reaction score
109
"Ultimate" means final, last, and infers perfection.

OMG what a waste of my 1000th post...
 

TheLegend

New Member
Reaction score
10
try it and see for yourself. the system now has no leaks, its better than the old Advanced third person camera system. About the ultimate thing, what should i call it "Reloaded" - sounds like i stole it... "Advanced" - taken... "TheLegend's ..." - kind of boring. Stop criticizing its name and tell me what you like and dont like in the system (for gods sake...). Now that we cleared that (Ignore the name since I cant change it) tell me your critics on the system (jass code) cause the triggers are just ads...
 

tommerbob

Minecraft. :D
Reaction score
110
I didn't read the code, but my first impression is why on earth would you mix GUI with Jass in a system? Use one or the other, not both.

AceHeart already made an awesome Third Person Cam system. Why is this one better (or comparable)?
 

TheLegend

New Member
Reaction score
10
the jass code is the system. It gives you the possibility to rotate the camera as you wish, if a unit is in the air (flight) it wont avoid destructibles and it will set the height there where it actualy is (not the ground like the previous cam system). The previous camera system could not be moved from one unit to another (thats the GUI I added) and could not be manualy rotated. This one wont avoid water as a blocker. You can add a trigger to change the max and min distance and stuff like that... I wont complain
 

Alince

New Member
Reaction score
0
I was wondering if you can guide me how to make it a free camera movment around the hero with zoom option, trying to make an RPG map =3, I tried to edit but I cant seem to out run that zoom disable ^^""
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top