System Third Person Camera

quraji

zap
Reaction score
144
I decided to actually try it :p

Pretty sweet, works well.

And the camera bob after zooming in or out is a way cool little detail :thup:
 

xxxtrickyxxx

(o Y o)
Reaction score
64
if you dont mind me asking, how exactly does the Z eye position work? I myself and a few others are trying to figure out a correct way to initiate z height values for a camera on hills, terrain etc but to no avail it will not calculate correctly do to the way the terrain is formed or whatever technicality it mentioned on wc3 campaigns, but if this camera fixed that then I am curious as to how the zoffset field fixed this problem. I am not 100% sure how Z eye position works but from what I understand it is the current cameras height? So if you are doing the current zoffset field + locz + camera height above ground - eye z then arent you simply canceling out the current cameras z height so it would be the same as locz + cam height?

Any insight on this would be greately appriciated. As of now, I have to terrian deform everything via triggers for the Z height and camera to work correctly.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
JASS:
private function Actions takes nothing returns nothing
    call ForGroup(CameraUnits, function Movement)
endfunction


That function is called every 0.15 seconds.
CameraUnits, as you may guess from the name, is a unit group holding the current "camera units" of all players.

For each unit, it runs this:
JASS:
private function MovementKeep 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 - 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



> if GetLocalPlayer() == GetOwningPlayer(u) then

Obviously, only change the camera if it is your unit...

> call PanCameraToTimed(GetUnitX(u), GetUnitY(u), Period)

The unit probably moved, here we are following it.

The "Period" btw, is 0.15, which is the periodicity of the previous function.
It just looks way better if the camera adjusts over time instead of instantly.
Yes, even with 0.15 it makes a major difference.

Faster is possible.
Slower obviously not, as we would have to wait every now and then for the camera to catch up with the unit... :p


> call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(u) + Rotate[GetPlayerId(GetOwningPlayer(u))], Period)

Have the camera look at whatever direction the unit is currently looking at.
Offset by the current personal rotation (limited to + or - 90 degrees by default).


> call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, Angle[GetPlayerId(GetOwningPlayer(u))], Period)
> call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, Distance[GetPlayerId(GetOwningPlayer(u))], Period)

Distance and angle start out as angle = 345 (somewhat down at ground level) and distance = 600 (close enough).
They determine how close or far, or how "up" and "down" you are to or looking at your unit.
I.e. the current "zoom". Which may be different for each player.


> call SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + GetLocationZ(l) + CameraHeight - GetCameraEyePositionZ(), Period)

The mystery action would be this one :p


All the details:

- call SetCameraField(CAMERA_FIELD_ZOFFSET,

Height from the ground.

- GetCameraField(CAMERA_FIELD_ZOFFSET)

Whatever height the camera currently is at.

- GetLocationZ(l)

The height of the terrain at the position of the unit.

- CameraHeight

Some default value, set to 300.
It determines the seen height above the unit.
A camera at ground level makes no sense.
So, we take the height at the ground, add this...

- GetCameraEyePositionZ(), Period)

... and subtract this to adjust for "other mysterious terrain height settings that mess up everything".

The best example here would be a flying unit and a cliff.
Ever tried it?
The unit will not come near the cliff, then suddenly jump up and continue.
Instead, it will slowly, as it gets closer to the cliff, climb up then continue once over the cliff.

Turns out the game adds an additional height map, specifically for fliers. (Actually, also used when simply moving around the map, clearly visible at a lower angle)
When they follow that map, they will notice cliffs or other bumps or hills, or ...

Why subtract it?
Because we want the camera at a fixed height.
Well, not exactly fixed, but fixed at a constant height in relation to your unit.
I.e. if the unit goes up, so does the camera. Same for down.

Or, maybe like this:
The camera at a given point already has some height that depends on the terrain but is not the terrain that you see.
Since we don't want that, we remove that special height.


Result: walking up or down is no problem.

Actually, it's still a problem on extreme hills for example.
But, then again, they look terrible no matter what...
A half-decent terrain, even with ramps and cliffs, some ups and downs, stairs, ... works just fine.



On a related note, even you managed to mess up your map completely, up to the point where no one knows anymore what you're talking about,
it's still possible to use the above function in "normal" JASS.
Give it a name that is not used yet, remove the "private", and just call it periodically for a bunch of units.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
Problem, yes, problem.

In almost 90% of every system I use, 'problem' comes up.

Take a look at my map, see that freaking problem of 288 JASS errors.

And yes, I'm using NewGen.
 

Attachments

  • DeadAce_Reloaded.w3x
    40.7 KB · Views: 307

Ryuu

I am back with Chocolate (:
Reaction score
64
Being a total noob to NewGen, I don't know there was this function.

But meh, I'm going to try it out.

EDIT: Err.. how do you do that? I viewed through the JassHelper menu but couldn't find it.

Could it be I'm actually using the wrong version.

While I download, please confirm that I'm not downloading for nothing.
 
S

Secondsight

Guest
First of all I really like this system! But second... I don't really know how to edit it a littlebit:(

I'm not very skilled at Jass or vJass so I'm afraid I have to ask this because I tried some things out already, but came to no better results.

I want to change it a bit, so the distance to the unit doesn't change when you press up or down. The thing I want is to always keep the distance 700 and let the up and down arrow's only change the AoA so you can watch above your unit too in some small area's where a camera behind the target would result into something very bad.

Any solutions for this?
 

Joker(Div)

Always Here..
Reaction score
86
Just edit the globals at the top to your likings...It doesn't require any JASSing skill at all, just uh...reading comprehension?
 
S

Secondsight

Guest
Just edit the globals at the top to your likings...It doesn't require any JASSing skill at all, just uh...reading comprehension?

I'm doing that like all the time. But it looks like the camera is not panned at the unit, but somewere behind the unit.:(
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Great system.
I suppose there is no easy way to control the Angle of Attack and smoothing factor? Also, no way to dynamically change camera's height?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Smoothing factor is something you usually only set once, around map init.

As for the others... well, there certainly is "a way".
Though, that would require some details on what that way is supposed to look like...
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
> Though, that would require some details on what that way is supposed to look like...

Well my 'ideal camera ' would be: A) instead of having the camera placed exactly behind the unit, it would be placed slightly above it. Thus watching it from an upper point of you. B)If the unit's flying height increase so should the camera's (and obviously when the unit's flying height is decreasing so could the camera's).
 

Weegee

Go Weegee!
Reaction score
102
Is it possible to make the camera turn "smoother"?


sorry if this is "necroposting"
 

GooS

Azrael
Reaction score
154
Is it possible to make the camera turn "smoother"?


sorry if this is "necroposting"

If that was necroposting this most definately is, BUT is there a way to change Z angle, not height, but the way you look down/up on the unit, setting height would make me loose sight, lower is kinda the opposite of what I want, so angle.

Namnlös.jpg

^
|
Pvetty pictcha
 

Viikuna

No Marlo no game.
Reaction score
265
It is possible to change z angle, but then again, you need to change z height too, or the camera goes inside the ground.
 

GooS

Azrael
Reaction score
154
It is possible to change z angle, but then again, you need to change z height too, or the camera goes inside the ground.

EDIT: Sry for being a retard.... after taking a closer look :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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