• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

First Person Camera System

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/...rials-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):


Update 1: Fixed every error Maker pointed out.
 

Attachments

  • First Person Camera System.w3x
    15.8 KB · Views: 881
Last edited by a moderator:
Level 37
Joined
Mar 6, 2006
Messages
9,240
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.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
~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)
 
Level 8
Joined
Apr 17, 2008
Messages
212
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
 
Level 1
Joined
Jul 28, 2014
Messages
6
BUG: Pls Fix

When going to a mountain or high cliffs the camera wont go up to pls fix, i cant upload my map with this bug....:vw_sad:
 
Top