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.
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.