System TheLegend's Advanced Third Person Camera

Status
Not open for further replies.

TheLegend

New Member
Reaction score
10
Advanced Third Person Camera
by TheLegend aka Codenamed​

After hours and hours of thinking, planning, fixing and editing I created my TheLegend's Third Person Camera System
Why is this system special?
- It can adjust the height of the camera according to the terrains
- It can be rotated using the arrow keys
- It can avoid destructibles that are behind the camera in order to avoid getting stuck in a wall, hill, tree, house... everything that has a pathing map "unwalkable"
- It can be turned off if it gets too annoying
- It can be moved from one unit to another
- It can adjust its rotation according to the angle of terrain - used for hill climbing and stuff like that
What can it do that others cannot...
It can adjust the rotation as mentioned and avoid other objects (I'm not quite sure if others used this)
What you need:
-NewGen World Editor
-vJass
-Ryoko's terrain pathing test map library (use the one I used in the map)
Info:
JASS:

//TheLegend's 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
//      camera_turned_off          Boolean Array - Checks if the player wants to turn the camera off
//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 if it leaks
//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
//Just to inform you:
//  The camera is able to:
//     -Avoid destructibles that are behind the camera, this is used to prevent the camera getting stuck in a house or tree
//     -Set its height according to the terrain and unit's flying height, this is used to prevent the camera getting stuck in a hill
//     -Set its angle according to the terrain, this is used to prevent players not seeing the top of the mountain when climbing it
//     -It can be switched from one unit to another
//     -The camera can be rotated using the arrow keys
//     -It can be switched off by pressing escape
//Give me credits if you use the camera please

System:
JASS:

//Main Camera System
//Made by TheLegend aka Codenamed
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
         // We dont want the camera to be run if there is no unit or if its disabeled
         if udg_camera_target_unit<i> != null and (GetWidgetLife(udg_camera_target_unit<i>) &gt; 0.405) and (udg_camera_turned_off<i> == false)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.20) //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.15) 
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit<i>) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.15) //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.10,true) //You can change the time if you want the cam to be faster or slower
    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></i>

The initialization trigger:
Trigger:
  • 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 &lt;gen&gt; the event (Player - (Picked player) Selects a unit)
          • Trigger - Add to TurnLEFT ON &lt;gen&gt; the event (Player - (Picked player) Presses the Left Arrow key)
          • Trigger - Add to TurnRIGHT ON &lt;gen&gt; the event (Player - (Picked player) Presses the Right Arrow key)
          • Trigger - Add to TurnLEFT OFF &lt;gen&gt; the event (Player - (Picked player) Releases the Left Arrow key)
          • Trigger - Add to TurnRIGHT OFF &lt;gen&gt; the event (Player - (Picked player) Releases the Right Arrow key)
          • Trigger - Add to Disable Camera &lt;gen&gt; the event (Player - (Picked player) skips a cinematic sequence)
      • -------- We set the main unit and the cam unit --------
      • Set camera_main_unit[1] = Blood Mage 0004 &lt;gen&gt;
      • Set camera_target_unit[1] = Blood Mage 0004 &lt;gen&gt;

The Unit Swicher:
Trigger:
  • 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


FAQ

Q: Does it work in multiplayer?
A: Yes it does just make sure you set the unit variables and change the value at
JASS:

    exitwhen i == 1
to the number of players that should have the camera
Q: Does it leak?
A: The system doesn't leak at all
Q: Why did you use GUI combined with JASS
A: Because it's sometimes easier for me to orientate in the code...
Q: How to add this to my map?
A: Declare all the variables needed for the system as said in Info and copy all the triggers. Don't forget the library in the map header...
Q: What do you mean by "can set its angle according to the terrain rotation"?
A: The camera system gives you the ability to see where you are going once on a hill with a great cliff angle. That means that even if the hill's side is 90 degree you will be able to see its top and not keep looking at its grass :)

Give me some credit if you use the system and feel free to ask me for help.
Finally, the test map (All triggers inside, even those not listed above):
View attachment TheLegend's TPCS.w3x
 
As far as I can see, your "JASS" is fake JASS. In that it's more or less converted GUI code and made to use natives instead of BJ's.

There are many, many mistakes that I can see. The biggest that stick out to me and that I care to point out is "Do nothing" and a few If statements. The conditions are just plain ugly.
 
The system was not converted but coded, remember that converted gui cannot normaly convert the if statements, i coded this system and there was no conversion at all. The gui part of the system was added later as I wanted to improve the system
 
I did not say it was completely converted code. I'm implying that it's almost as bad as converted code.

JASS:
.

                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</i>


->

JASS:
.
                if ( (IsTerrainWalkable(x1, y1) or IsTerrainDeepWater(x1, y1) or GetUnitFlyHeight(udg_camera_target_unit<i>) &gt; 0) and (v &lt; 450) ) then
                    set v = v + 25
                else
                    exitwhen true
                endif
</i>


There are a lot of things wrong with your code or things that can be done much better.

I suggest you learn a bit more before submitting systems.

Also, I don't condone the use of GUI when GUI makes your code a thousand times worse.

You should get NewGen as well. Convert all of this to vJASS and it would be so much better (vJASS almost forces better conventions, habits, etc).
 
i am using NewGen :) Oh and thanx for the tips, im new with jass and i know my code sucks sometimes but the idea is great... dont you think. i mean having a camera system that adjusts the angle of the camera and can be turned of isnt a small thing
 
Well it's been done before to be honest. It's not that special anymore. Just about everything has been thought of now-a-days.

If you're using NewGen, you should make it into a library with vJASS.

It structures code better than the current setup.
 
Status
Not open for further replies.
General chit-chat
Help Users
  • The Helper The Helper:
    It is weird seeing a way more realistic users online number
  • The Helper The Helper:
    Happy Tuesday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:

      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