System Third Person Camera

lbebusiness

New Member
Reaction score
3
To get flying unit height AND terrain height

Okay for those of you asking about having the camera that can go up and down hills cliffs etc with the unit AND adjust with a units height and/or flying height change this part of code of AceHeart's system :



with this:


For those of you who want what I just posted and the settings for a "above but behind the unit" look just replace the enitre system with this:

JASS:
library TPC initializer Init

globals
    // How often the camera is adjusted. Every 0.15 seconds is plenty fast enough
    private constant real Period = 0.15

    // General camera options
    private constant real CameraHeight = 290
    private constant real CameraAngle = 347
    private constant real CameraDistance = 600

	// Arrow keys can be used to rotate and zoom
	private constant boolean AllowArrowKeys = true
	// Escape resets the camera to "general camera options"
	private constant boolean AllowEscape = true

    // Wan't to be able to turn it on or off?
	private constant string Command = "-camera"
	private constant boolean AllowCommand = true

    // Optionally stops the camera if the current camera unit dies
	private constant boolean RemoveOnDeath = true

    // Rotation is either free...
    private constant boolean AllowFreeRotation = false
    // ... or limited to +/- this:
	private constant real CameraMaxRotate = 120

    // You can change this... but should just leave them
	private constant real CameraMaxDistance = 1200
	private constant real CameraMinDistance = 150

    // DON'T touch anything here
    private group CameraUnits = CreateGroup()
    private group CameraUnits_start = CreateGroup()
    private real array Rotate
    private real array Distance
    private real array Angle
    private boolean array DoLeft
    private boolean array DoRight
    private boolean array DoDown
    private boolean array DoUp
endglobals

private function CameraRemovePlayer_function takes nothing returns nothing
    if GetOwningPlayer(GetEnumUnit()) == bj_forceRandomCurrentPick then
        call GroupRemoveUnit(CameraUnits_start, GetEnumUnit())
        call GroupRemoveUnit(CameraUnits, GetEnumUnit())
    endif
endfunction

function TPCRemovePlayer takes player p returns nothing
    set bj_forceRandomCurrentPick = p
    call ForGroup(CameraUnits, function CameraRemovePlayer_function)
    call ForGroup(CameraUnits_start, function CameraRemovePlayer_function)
    if GetLocalPlayer() == p then
        call ResetToGameCamera(1.5)
    endif
endfunction

function TPCAdd takes unit u returns nothing
    local player p = GetOwningPlayer(u)
	local integer i = GetPlayerId(p)
    call TPCRemovePlayer(p)
	set Rotate<i> = 0
	set Angle<i> = CameraAngle
	set Distance<i> = CameraDistance
    call GroupAddUnit(CameraUnits_start, u)
    call GroupAddUnit(CameraUnits, u)
    set p = null
endfunction

function TPCRemove takes unit u returns nothing
    call GroupRemoveUnit(CameraUnits_start, u)
    call GroupRemoveUnit(CameraUnits, u)
    if GetLocalPlayer() == GetOwningPlayer(u) then
        call ResetToGameCamera(1.5)
    endif
endfunction

function TPCRemoveAll takes nothing returns nothing
    call GroupClear(CameraUnits)
    call GroupClear(CameraUnits_start)
endfunction

private function Death takes nothing returns nothing
    if IsUnitInGroup(GetTriggerUnit(), CameraUnits_start) or IsUnitInGroup(GetTriggerUnit(), CameraUnits) then
        call TPCRemove(GetTriggerUnit())
    endif
endfunction

private function Movement takes nothing returns nothing
    local unit u = GetEnumUnit()
    local location l = GetUnitLoc(u)
    if GetLocalPlayer() == GetOwningPlayer(u) then
        call PanCameraToTimed(GetUnitX(u), GetUnitY(u), Period)
        call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(u) + Rotate[GetPlayerId(GetOwningPlayer(u))], Period)
        call SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + GetLocationZ(l) + CameraHeight + (GetUnitFlyHeight(u) ) - GetCameraEyePositionZ(), Period)
        call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, Angle[GetPlayerId(GetOwningPlayer(u))], Period)
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, Distance[GetPlayerId(GetOwningPlayer(u))], Period)
    endif
    call RemoveLocation(l)
    set u = null
    set l = null
endfunction

private function Actions takes nothing returns nothing
    call ForGroup(CameraUnits, function Movement)
endfunction

private function usesCamera takes nothing returns nothing
    if GetOwningPlayer(GetEnumUnit()) == GetTriggerPlayer() then
        set bj_isUnitGroupDeadResult = false
    endif
endfunction

private function CameraOn takes nothing returns nothing
	local integer i = GetPlayerId(GetTriggerPlayer())
    if GetOwningPlayer(GetEnumUnit()) == GetTriggerPlayer() then
        set Rotate<i> = 0
        set Angle<i> = CameraAngle
        set Distance<i> = CameraDistance
        call GroupAddUnit(CameraUnits,  GetEnumUnit())
    endif
endfunction

private function CameraOff takes nothing returns nothing
    if GetOwningPlayer(GetEnumUnit()) == GetTriggerPlayer() then
        call GroupRemoveUnit(CameraUnits, GetEnumUnit())
    endif
endfunction

private function ChatActions takes nothing returns nothing
    set bj_isUnitGroupDeadResult = true
    call ForGroup(CameraUnits, function usesCamera)
    if bj_isUnitGroupDeadResult then
        call ForGroup(CameraUnits_start, function CameraOn)
    else
        call ForGroup(CameraUnits, function CameraOff)
        if GetLocalPlayer() == GetTriggerPlayer() then
            call ResetToGameCamera(1.5)
        endif
    endif
endfunction

private function KeyLeft takes nothing returns nothing
    set DoLeft[GetPlayerId(GetTriggerPlayer())] = not DoLeft[GetPlayerId(GetTriggerPlayer())]
endfunction
private function KeyRight takes nothing returns nothing
    set DoRight[GetPlayerId(GetTriggerPlayer())] = not DoRight[GetPlayerId(GetTriggerPlayer())]
endfunction
private function KeyDown takes nothing returns nothing
    set DoDown[GetPlayerId(GetTriggerPlayer())] = not DoDown[GetPlayerId(GetTriggerPlayer())]
endfunction
private function KeyUp takes nothing returns nothing
    set DoUp[GetPlayerId(GetTriggerPlayer())] = not DoUp[GetPlayerId(GetTriggerPlayer())]
endfunction

private function DoKeys takes nothing returns nothing
    local integer i = 0
    loop
    	if DoLeft<i> then
    		if AllowFreeRotation or Rotate<i> &lt; CameraMaxRotate then
    			set Rotate<i> = Rotate<i> + 8
                if Rotate<i> &gt; 360 then
                    set Rotate<i> = Rotate<i> - 360
                endif
    		endif
    	endif
    	if DoRight<i> then
    		if AllowFreeRotation or Rotate<i> &gt; -CameraMaxRotate then
    			set Rotate<i> = Rotate<i> - 8
                if Rotate<i> &lt; -360 then
                    set Rotate<i> = Rotate<i> + 360
                endif
    		endif
    	endif
    	if DoDown<i> then
    		if Distance<i> &lt; CameraMaxDistance then
    			set Distance<i> = Distance<i> + 25
    			set Angle<i> = Angle<i> + 0.35
    		endif
    	endif
    	if DoUp<i> then
    		if Distance<i> &gt; CameraMinDistance then
    			set Distance<i> = Distance<i> - 25
    			set Angle<i> = Angle<i> - 0.35
    		endif
    	endif
    	set i = i + 1
    	exitwhen i &gt;= 12
    endloop
endfunction

private function Escape takes nothing returns nothing
	local integer i = GetPlayerId(GetTriggerPlayer())
	set Rotate<i> = 0
	set Angle<i> = CameraAngle
	set Distance<i> = CameraDistance
endfunction

private function Init takes nothing returns nothing
    local integer i
    local trigger t = CreateTrigger()
	local trigger t1 = CreateTrigger()
	local trigger t2 = CreateTrigger()
	local trigger t3 = CreateTrigger()
	local trigger t4 = CreateTrigger()
    local timer m
    local player p
    call TriggerRegisterTimerEventPeriodic(t, Period)
    call TriggerAddAction(t, function Actions)
    if AllowCommand then
        set t = CreateTrigger()
        call TriggerAddAction(t, function ChatActions)
        set i = 0
        loop
            call TriggerRegisterPlayerChatEvent(t, Player(i), Command, true)
            set i = i + 1
            exitwhen i &gt;= 12
        endloop
	endif
	if RemoveOnDeath then
	    set t = CreateTrigger()
	    call TriggerAddAction(t, function Death)
	    set i = 0
	    loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
            set i = i + 1
            exitwhen i &gt;= 12
        endloop
	endif
	call TriggerAddAction(t1, function KeyLeft)
	call TriggerAddAction(t2, function KeyRight)
	call TriggerAddAction(t3, function KeyDown)
	call TriggerAddAction(t4, function KeyUp)
	set i = 0
	loop
		set Rotate<i> = 0
		set Distance<i> = CameraDistance
		set Angle<i> = CameraAngle
		set DoLeft<i> = false
		set DoRight<i> = false
		set DoDown<i> = false
		set DoUp<i> = false
		set p = Player(i)
		if AllowArrowKeys then
			call TriggerRegisterPlayerEvent(t1, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
			call TriggerRegisterPlayerEvent(t1, p, EVENT_PLAYER_ARROW_LEFT_UP)

			call TriggerRegisterPlayerEvent(t2, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
			call TriggerRegisterPlayerEvent(t2, p, EVENT_PLAYER_ARROW_RIGHT_UP)

			call TriggerRegisterPlayerEvent(t3, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
			call TriggerRegisterPlayerEvent(t3, p, EVENT_PLAYER_ARROW_DOWN_UP)

			call TriggerRegisterPlayerEvent(t4, p, EVENT_PLAYER_ARROW_UP_DOWN)
			call TriggerRegisterPlayerEvent(t4, p, EVENT_PLAYER_ARROW_UP_UP)
		endif
		set i = i + 1
		exitwhen i &gt;= 12
	endloop
    set m = CreateTimer()
	call TimerStart(m, 0.05, true, function DoKeys)
	set m = null

	if AllowEscape then
	    set t = CreateTrigger()
	    call TriggerAddAction(t, function Escape)
	    set i = 0
	    loop
		    call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_END_CINEMATIC)
            set i = i + 1
            exitwhen i &gt;= 12
        endloop
	endif


    set t = null
    set t1 = null
    set t2 = null
    set t3 = null
    set t4 = null
    set p = null
endfunction</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


Btw here is an attachment of a map that I am making in which I used aceheart's system (with many other systems)
His system has been changed and made modular and made so camera changes everytime you select a new unit. Also for some reason if you select more than one unit it seems to default pan to the highest ranking unit...

just copy the trigger folder called "Camera System [Modular]" to your map

*thanks aceheart for map header info. moved code and reposted map. much simpler for others to copy and past too!
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Libraries can be put anywhere.
NewGen takes care of moving them to the top of the map script.

Along with the "requires" keyword if you need them in a particular order.
 

lbebusiness

New Member
Reaction score
3
Thank you VERY MUCH

I was using newgen but when I first started using your system I was still new to warcraft mapping (old time starcraft) and thought the "errors" where do to me placing it in as a trigger. And never messed around "much" once it worked.
Thank you.

Err. Uh how do I get more space for uploading maps and stuff? My map post here took just about all of my storage lol.
 

Tooblet

Active Member
Reaction score
6
err.. I have a little problem with this system.

It works perfectly and smooth and i've configured it exactly as I want it.
But if I press the arrowkeys for zooming or rotation when the heroes of my map dies, and then revives him. The keys really mess up everything.

Example:
I walk around my rpg with this camera, and I rotate the camera at the exact time my hero dies.
Then I have this dialog systemwhere I press a button, he revives and then the camera spins either to the max limit of 90 degrees, Or if I set it to just beeing free, it keeps on rotating forever.
Same goes for zooming, If I zoom in or out when hero dies, It gets stuck in the max zoom when I later revive the hero.

Any idéa on why this happens? and if so, solution would be sweet :)
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Event:
- A unit dies
Conditions:
- ((Triggering unit) is a Hero) equal to true
Action:
- Custom script: call TPCRemove( GetTriggerUnit() )

And put him back when he "a unit finishes reviving".
 

Tooblet

Active Member
Reaction score
6
> Event:
- A unit dies
Conditions:
- ((Triggering unit) is a Hero) equal to true
Action:
- Custom script: call TPCRemove( GetTriggerUnit() )

Sorry Doesn't work.
I added it after revive, also tried adding right after removing it.
no sucess.
I guess the arrowkey push gets stored or something.
It's really failing. Tried a couple of things. Still, When revived, starts spinning right away.

EDIT: It's kinda wierd cause if I press an arrowkey when a friends hero dies, it starts to loop aswell.
 

Tooblet

Active Member
Reaction score
6
Bumping cause I really need a solution :p
I was thinking maybe you need to have an "release arrow" kind of thing
in there.
I don't know any jass though so I wouldn't know how to fix it.

I think aceheart should update his system since it has a major bug in it and
isn't working properly :/
 

Tooblet

Active Member
Reaction score
6
wrong

No im sorry.. I even tried removing TPC and then revive hero, wait 30 secs
and then add it again, as soon as the TPC gets added, the camera starts spinning like crazy if I held down the arrow key while dying.
 

Tooblet

Active Member
Reaction score
6
I have found the problem I have that is bugging in this system.
as I've said I have tried about anything to get rid of this "endless loop" problem with the arrow keys.
removing, adding, setting true on "remove on death" and then adding, waiting alot of time, remove all, adding. It still bugs.

So I got pissed and removed the whole thing, and then re-imported it to my map.
Still the same problem..

Then I tested alot of things out in your Demomap and found it! :D:D

In my map I have a dialog showing up when a hero dies. And THAT'S what is causing the system to think that I'm constantly pressing down an arrowkey.

I want to keep my dialog system I have though, So how would I solve this problem?

EDIT: I was thinking maybe forcing the esc-button function or something when hero dies. I don't know how I would do that though because I don't know any jass.
 

Tooblet

Active Member
Reaction score
6
Yeah sure a wait works for people who maybe press down the button and happens to die and still holds it down while dying..
But even with a 10 second wait when dead, if i press down and the dialog shows up, It bugs and thinks I'm pressing down the arrow key all the time :/

ty for helping though, but I really want to use this system since I consider this the best camera out there. (even with the bug :p)
 

Tooblet

Active Member
Reaction score
6
mysterium

Dear Aceheart.. :D

I have a question.
Is it possible to somehow setting "allow key actions" booleans
to False when my heroes die. and then setting them to true when they revive?
Cause I don't even need to have the camera system ON. If i press an arrowkey while the dialog shows up, it will bug the camera as soon as I apply it.

I can TCPRemove (or making it remove on death).. wait 20 secs for dialog, presskey when dialog comes up, ress hero, walk around, wait 30 secs and TCPAdd, and it will start spinning .. :p

So I was thinking setting key thingies to False somehow, I only know GUI so..
maybe that would work.
 

Callmebob

New Member
Reaction score
1
Too smart for me!
I can't even figure out how to get it working! Makes me feel really noobish!

Anyone feel like giving a Step by Step how-to for your everyday idiot? If not, ill probably go back to banging my head against a wall :p.
 

terrorfrix

New Member
Reaction score
0
i got a probem with installing or insufficient knowledge but anyway i need help so i need someone to show me how to inport this in another map(rpg) without getting error
 

tommerbob

Minecraft. :D
Reaction score
110
i got a probem with installing or insufficient knowledge but anyway i need help so i need someone to show me how to inport this in another map(rpg) without getting error

You need JassNewGen. Then just follow Aceheart's instructions on the first post. Pretty simple.
 
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