PDA

View Full Version : First Person Camera System


Darkzealot_128
11-23-2010, 05:20 AM
First Person Camera System:

Introduction:

Before reading this tutorial, please do not go “Ughhh not another tutorial on a first person camera system!!” (http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/creating-first-person-camera-93891/). I created a system that works for every player, does not lag (not that the other one on Hive does), has a map file attached, has animations playing so you look like you are actually walking to the other players and has some comments in the triggering to guide you.

What is a first person camera system?

To the people who don’t know, a first person camera system is like a first person shooter, making it look like you are looking through the eyes of the person you are playing as. They are great to use for a Warcraft 3 map because it makes your map more unique and exciting to play. But the disadvantages of using a first person camera are that it can not be used on a hilly surface (it goes through the ground and everything turns black), it can’t be used on a large unit (because you can see the inside of the unit’s body), and it makes picking up items harder.

The system:

Coming first is the most important trigger, the loop, then following that are the movement triggers and the attack trigger:

If you hold down the left/right/up/back arrow key it sets the boolean to true and if the boolean is true in the loop trigger your unit turns left/right/up/back. Once you let go of one of the arrow keys though, it sets the boolean of the direction to false deactivating the direction actions.

configuration
Events
Map initialization
Conditions
Actions
-------- Below you can set the units you want each player to have their camera system attached to. --------
Set unit[1] = Test Unit 0001 <gen>
-------- Adding the events --------
Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Picked player) controller) Equal to User
Then - Actions
-------- Putting events into the triggers, unneccesary events for players who aren't playing are not created. --------
Trigger - Add to move 1 <gen> the event (Player - (Picked player) Presses the Left Arrow key)
Trigger - Add to move 2 <gen> the event (Player - (Picked player) Releases the Left Arrow key)
Trigger - Add to move 3 <gen> the event (Player - (Picked player) Presses the Right Arrow key)
Trigger - Add to move 4 <gen> the event (Player - (Picked player) Releases the Right Arrow key)
Trigger - Add to move 5 <gen> the event (Player - (Picked player) Presses the Up Arrow key)
Trigger - Add to move 6 <gen> the event (Player - (Picked player) Releases the Up Arrow key)
Trigger - Add to move 7 <gen> the event (Player - (Picked player) Presses the Down Arrow key)
Trigger - Add to move 8 <gen> the event (Player - (Picked player) Releases the Down Arrow key)
Else - Actions


main trigger
Events
Time - Every 0.03 seconds of game time
Conditions
Actions
-------- Above it doesn't have to be every 0.03 seconds, you can change it to 0.01 but I find it laggy. --------
-------- I recommend leaving the stuff below unless you want to fiddle around with the camera reals (but I think it is good the way it is) --------
-------- And no this player group doesn't leak because it is (all players). --------
Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
Set playernumber = (Player number of (Picked player))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
isgoingforward[playernumber] Equal to True
Then - Actions
-------- Removing the location leak and moving te unit the camera of the player is attached to. You can edit the offset value to change the speed too. --------
Set fpsloc1 = Position of unit[playernumber]
Set fpsloc2 = (fpsloc1 offset by 3.00 towards (Facing of unit[playernumber]) degrees))
Unit - Move unit[playernumber] instantly to fpsloc2
Custom script: call RemoveLocation(udg_fpsloc1)
Custom script: call RemoveLocation(udg_fpsloc2)
-------- Playing an animation to make it look like you are actually walking to the other players. --------
Animation - Play unit[playernumber]'s walk animation
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
ismovingbackwards[playernumber] Equal to True
Then - Actions
-------- Removing the location leak and moving the unit the camera of the player is attached to. You can edit the offset value to change the speed too. --------
Set fpsloc1 = Position of unit[playernumber]
Set fpsloc2 = (fpsloc1 offset by -3.00 towards (Facing of unit[playernumber]) degrees)
Unit - Move unit[playernumber] instantly to fpsloc2
Custom script: call RemoveLocation(udg_fpsloc1)
Custom script: call RemoveLocation(udg_fpsloc2)
-------- Playing an animation to make it look like you are actually walking to the other players. --------
Animation - Play unit[playernumber]'s walk animation
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
isturningleft[playernumber] Equal to True
Then - Actions
Set turning[playernumber] = (turning[playernumber] + 1.00)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
isturningright[playernumber] Equal to True
Then - Actions
Set turning[playernumber] = (turning[playernumber] - 1.00)
Else - Actions
Unit - Make unit[playernumber] face turning[playernumber] over 0.01 seconds
-------- You can fiddle with the real values, but it is probably fine the way it is. --------
Camera - Set (Picked player)'s camera Distance to target to 0.00 over 0.00 seconds
Camera - Set (Picked player)'s camera Angle of attack to 350.00 over 0.00 seconds
Camera - Set (Picked player)'s camera Rotation to (Facing of unit[(Player number of (Picked player))]) over 0.50 seconds
Camera - Set (Picked player)'s camera Height Offset to 110.00 over 0.00 seconds
-------- Removing the 2nd location leak --------
Set fpsloc1 = Position of unit[playernumber]
Set fpsloc2 = (fpsloc1 offset by 50.00 towards (Facing of unit[playernumber]) degrees)
Camera - Pan camera for (Picked player) to fpsloc2 over 0.00 seconds
Custom script: call RemoveLocation(udg_fpsloc1)
Custom script: call RemoveLocation(udg_fpsloc2)
-------- Not compulsory, but without it it is nearly impossible to select a unit --------
Selection - Select unit[(Player number of (Picked player))] for (Picked player)


move 1
Events
Conditions
Actions
Set isturningleft[(Player number of (Triggering player))] = True


move 2
Events
Conditions
Actions
Set isturningleft[(Player number of (Triggering player))] = False


move 3
Events
Conditions
Actions
Set isturningright[(Player number of (Triggering player))] = True


move 4
Events
Conditions
Actions
Set isturningright[(Player number of (Triggering player))] = False


move 5
Events
Conditions
Actions
Set isgoingforward[(Player number of (Triggering player))] = True


move 6
Events
Conditions
Actions
Set isgoingforward[(Player number of (Triggering player))] = False
-------- Without this animation, the unit is not going to stop the walking animation because the walk animations queue up too fast --------
Animation - Reset unit[(Player number of (Picked player))]'s animation


move 7
Events
Conditions
Actions
Set ismovingbackwards[(Player number of (Triggering player))] = True



move 8
Events
Conditions
Actions
Set ismovingbackwards[(Player number of (Triggering player))] = False
-------- Without this animation, the unit is not going to stop the walking animation because the walk animations queue up too fast --------
Animation - Reset unit[(Player number of (Triggering player))]'s animation



Up = Move forward
Right = Look right
Left = Look left
Down = Attack

Stopping your unit:

You may have seen that the camera unit can go through things and get out of the map, if you would like to stop the camera unit, put a solid unit/doodad in his way.

End:

You don’t need to give credit for the system (credit is appreciated) and I hope you have a good time using it for your map (I believe there should be more first person games out there). Document is at the bottom.

:thumbs_up:

System in use (It's the same system but it's on a different testmap and is combined to my reload system because i'm going to use this for my other current project):

http://www.youtube.com/watch?v=IDqqYoNpiGU

Update 1: Fixed every error Maker pointed out.

Maker
11-23-2010, 06:32 AM
Leak:
Set leaklocation[(Player number of (Picked player))] = ((Position of unit[(Player number of (Picked player))]) offset by 3.00 towards (Facing of unit[(Player number of (Picked player))]) degrees)
Position of unit is one point and the offset point is another. Also no need to use array here.

Leak:
Camera - Pan camera for (Picked player) to ((Position of unit[(Player number of (Picked player))]) offset by 50.00 towards (Facing of unit[(Player number of (Picked player))]) degrees) over 0.00 seconds


Save the Player number to a variable, and use the variable instead of calling the function over and over again.

You are adding the events every 0.03 seconds, that makes no sense.

I'd leave this out of the loop also:
((Picked player) controller) Equal to User

Where's my backwards movement?

Why is this looped from 1 to 12?
attack 3
Events
Unit - A unit Is attacked
Conditions
Actions
For each (Integer loop) from 1 to 12, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
unitisattacking[loop] Equal to False
(Attacking unit) Equal to unit[loop]
Then - Actions
Unit - Order (Attacking unit) to Stop
Else - Actions


There should be a configuration trigger.

If there's any height variation, the camera will bug.

Darkzealot_128
11-23-2010, 06:34 AM
Thanks maker, going to fix. I didn't use my brain when I added the events. o.o

Edit: Fixed EVERYTHING you told me to.

And I know about the height variation thing I warned that you need to use it on flat terrain.

PurgeandFire
12-23-2010, 06:23 AM
Hm... I guess the trigger comments explain what is being done. And it is pretty self-explanatory. I still feel like this is more of a system than a tutorial, but it is a pretty common subject and the fixes have been made, so ~approved.

Maker
12-23-2010, 10:23 AM
~approved.

Set leaklocation = ((Position of unit[playernumber]) offset by 3.00 towards (Facing of unit[playernumber]) degrees)

Set leaklocation2 = ((Position of unit[playernumber]) offset by -3.00 towards (Facing of unit[playernumber]) degrees)

Set leaklocation3 = ((Position of unit[playernumber]) offset by 50.00 towards (Facing of unit[playernumber]) degrees)

PurgeandFire
12-26-2010, 06:27 AM
Argh, wasn't paying attention. I'll fix that.

EDIT: Fixed.

nethead01
01-20-2011, 05:27 AM
Thanks for the very nice tutorial! It helped me out alot.. thanks again

Magamdy
01-20-2011, 02:41 PM
Hi. Cool you made another system. And this looks a lot more complex than what I made o_O You however say my system lags? The movement of you camera is smoother if that's what you mean, I wouldn't call it lag. And can be used by everyone? I don't see how my system can't be used by everyone :\ Also, I had a map file attached, but it was deleted cuz it was actually an unfinished map the system was used in.

Also I wouln't call it an improvement. Some things like arrow key movement are cool, but I traded that for look up and down. Its cool you can keep the unit at full size and show a weapon gotta give u that lol. But that will get harder when your hero gets different weapons, since seeing a sword when using a bow doesnt make sense lol.

Anyway thats what I wanted to say ^^ Keep up teh work :D

Orcnet
01-25-2011, 07:40 AM
this is a different version of a camera style. very nice! :grin: