• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Camera Help

Status
Not open for further replies.
Level 1
Joined
Feb 23, 2015
Messages
1
Hey all,

I've found this camera and arrow key movement system over in the spells section: Cam System v3 and I need a bit of help making it work if anyone is willing. Not too sure how to attach the camera and movement system itself to a unit of my choosing. If this is the wrong place to post this I do apologize. Any help is appreciated. Thanks very much.
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
1. That system is pretty old. I can't say for certain, but there is probably something newer/better or at least something that isn't written in fucking zinc. I'm honestly not sure if zinc code even compiles in the new WE, as that used to be a part of the JNGP WE back in the day when zinc was relevant.

2. At the bottom of every resource post there are a few links, one of which says Preview Triggers. You can always click on that to see if there was an example trigger uploaded to the resource that simply isn't mentioned in the main description. In this case you're in luck; we find:
JASS:
library CamExampele initializer init requires CameraSystem

    private function rotate takes nothing returns nothing
        // If the pressed key was down, we will rotate the unit by 180°
        // GetTriggerEventId() returns the id so we can check which arrow was pressed or released.
        if GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_DOWN then
            call SetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow, GetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow) + 180)
        endif
    endfunction

    private function init takes nothing returns nothing
        local group g = CreateGroup()
        local unit  u
        
        // Creating the camera struct for Player 1 (Red)
        local CAMERA cam = CAMERA.create(Player(0))
        
        // Getting the hero of Player 1
        call GroupEnumUnitsInRange(g, 0, 0, 999999, null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null

            if GetUnitTypeId(u) == 'O000' then
                exitwhen true
            endif
            
            call GroupRemoveUnit(g, u)
        endloop
        call DestroyGroup(g)
        
        // Setting the unit which the camera follows to the hero we just found out
        set cam.toFollow = u
        // Change the camera to active
        set cam.active = true
        // This is a member of the keyboard plugin. We have to set a animationIndex (for most units) and a animation duration (for all units).
        // How do you get the index? Seriously. No idea. Play around with numbers from 0 to whatever until you get a good-looking walk
        // animation
        // How do you get the animation duration?
        // Place a unit in the editor, click on it and click through it's animations until you find the walk animation. Write down the duration
        // and you're done.
        set cam.animationDur = 0.733
        
        // Registering a new key event is easy - just like this.
        call cam.registerKeyEvent(function rotate)
        
        // Nulling is cool.
        set g = null
        set u = null
    endfunction
    
endlibrary
With this in mind we can extract the important bits. The function rotate at the top is custom behavior for what happens when the down arrow key is pressed; in the example code pressing the down arrow will flip the unit around. If you don't want this behavior, you need not create the function and register it (that happens near the end). The stuff about the group is just setup from the example map to find the player's hero unit; it can be ignored.

Then you want to combine all this stuff into a function that takes a unit as an argument, so that a camera can be attached to that unit:
JASS:
library YourCamStuff requires CameraSystem
    private function rotate takes nothing returns nothing
        // If the pressed key was down, we will rotate the unit by 180°
        // GetTriggerEventId() returns the id so we can check which arrow was pressed or released.
        if GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_DOWN then
            call SetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow, GetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow) + 180)
        endif
    endfunction

    function StartCamOnUnit takes unit u returns nothing
        // Creating the camera struct for the owning player
        local CAMERA cam = CAMERA.create(GetOwningPlayer(u))
        
        // Setting the unit which the camera follows to the hero we just found out
        set cam.toFollow = u
        // Change the camera to active
        set cam.active = true
        // This is a member of the keyboard plugin. We have to set a animationIndex (for most units) and a animation duration (for all units).
        // How do you get the index? Seriously. No idea. Play around with numbers from 0 to whatever until you get a good-looking walk
        // animation
        // How do you get the animation duration?
        // Place a unit in the editor, click on it and click through it's animations until you find the walk animation. Write down the duration
        // and you're done.
        set cam.animationIndex = 6 //this is the default value given in the system, and this value is assigned automatically; however, you may
                                   //want to set it to something else, as per the comment above. Pyrogasm added this line for clarity.
        set cam.animationDur = 0.733
        
        // Registering a new key event is easy - just like this.
        call cam.registerKeyEvent(function rotate)
    endfunction
endlibrary

Now if you know JASS then just call the function like you expect with the unit as an argument. If you're using GUI I suggest you do this:
  • Set TempUnit = The unit that you want to lock the camera to for its owner, however you get that
  • Custom script: call StartCamOnUnit(udg_TempUnit) //match the variable name in here to the variable name of the unit variable you're using, but keep the udg_ prefix
 
Status
Not open for further replies.
Top