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
 

Sevion

The DIY Ninja
Reaction score
413
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.
 

TheLegend

New Member
Reaction score
10
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
 

Sevion

The DIY Ninja
Reaction score
413
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).
 

TheLegend

New Member
Reaction score
10
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
 

Sevion

The DIY Ninja
Reaction score
413
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
  • 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

      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