1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Welcome to the new Hive! Be advised that we're still working on the site. There are still many rough edges, so please bear with us.
    Dismiss Notice
  3. The 14th Icon Contest is still in progress (and may be extended). You can still make it in time.
    Dismiss Notice
  4. The 25th Texturing Contest has started! Contestants are to create a skin representing a dark elf person/being or any construct related to it using the vanilla models or the custom ones found on the site.
    Dismiss Notice
  5. Buy it, use it, break it, fix it, trash it, change it, mail - upgrade it. Join (Optionally) Paired Techtree Contest #11 - Techno Magic now!
    Dismiss Notice
  6. Voting squad, line up! Cast your vote on the poll for Modeling Contest #29 - Squads!
    Dismiss Notice
  7. Hero Contest #8 is up and running! This time it's a joint contest between artists and coders. Go here for team matchmaking.
    Dismiss Notice
  8. The poll for the theme of our StarCraft II Terraining Contest is up. Cast your note now!
    Dismiss Notice
  9. The ninth Concept Art Contest has launched. Enter now!
    Dismiss Notice
  10. The member Kam is making HIVE coasters. Take a look. For every coaster you buy, Hive gets $1.
    Dismiss Notice

First Person Camera System

Discussion in 'General Mapping Tutorials' started by Darkzealot_128, Nov 23, 2010.

  1. Darkzealot_128

    Darkzealot_128
    Joined:
    Jun 29, 2010
    Messages:
    747
    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:
    Triggers

    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.
     

    Attached Files:

    Last edited by a moderator: Dec 26, 2010
  2. Maker

    Maker

    Code Moderator

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    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?
    Trigger
    • 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.
     
  3. Darkzealot_128

    Darkzealot_128
    Joined:
    Jun 29, 2010
    Messages:
    747
    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.
     
    Last edited: Nov 23, 2010
  4. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,100
    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.
     
  5. Maker

    Maker

    Code Moderator

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    • 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)
     
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,100
    Argh, wasn't paying attention. I'll fix that.

    EDIT: Fixed.
     
  7. nethead01

    nethead01
    Joined:
    Jan 20, 2011
    Messages:
    1
    nice

    Thanks for the very nice tutorial! It helped me out alot.. thanks again
     
  8. Magamdy

    Magamdy
    Joined:
    Apr 17, 2008
    Messages:
    211
    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
     
  9. Orcnet

    Orcnet
    Joined:
    Jul 31, 2010
    Messages:
    3,875
    this is a different version of a camera style. very nice! :grin:
     
  10. Nickz

    Nickz
    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: