• 🏆 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!

1st Person Shooter Camera and Movement

Status
Not open for further replies.
Level 4
Joined
Jul 15, 2009
Messages
29
Okay. So everyone wants to know how to make a first person camera and movement system, and keeps asking the same questions. So I will make this tutorial as simple and as easy as possible so as to help all the WE n00bs.

Lets start out with movement.

1: Create four boolean array variables: Up, Down, Left, Right
2: Make respective triggers for each like this:

Up:
  • Events - Player - Player 1 Presses the Up arrow key
  • Player - Player 2 Presses the Up arrow key
  • Player - Player 3 Presses the Up arrow key
  • Conditions -
  • Actions - Set Up[(Player number of (Triggering player))] = True
Up Release:
  • Events - Player - Player 1 Releases the Up arrow key
  • Player - Player 2 Releases the Up arrow key
  • Player - Player 3 Releases the Up arrow key
  • Conditions -
  • Actions - Set Up[(Player number of (Triggering player))] = False
Again, do this for every arrow key.

3: Create a Unit Array variable named Hero
4: Create a Timer variable named Do_Stuff

Make these triggers:

Initialization:
  • Events - Map Initialization
  • Conditions -
  • Actions - Set Hero[(Player number of (Player Group (Player 1 Red)))] to (Your Dude)
  • Set Hero[(Player number of (Player Group (Player 2 Blue)))] to (His Dude)
  • Set Hero[(Player number of (Player Group (Player 3 Green)))] to (His Dude)
  • Countdown Timer - Start (Do_Stuff) as a Repeating timer that will expire in 0.10 seconds
Movement and Camera:
  • Events - Time - Do_Stuff expires
  • Conditions -
  • Actions - Player Group - pick all players in (All Players) and do actions:
  • Loop - actions
  • If (All conditions are True) then do (Then actions) else do (Else Actions):
  • If - Conditions
  • Hero[(Player number of (Picked player))] is alive = True
  • Then - Actions
  • -----moving-----
  • If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = True
  • Left[Player number of (Picked player))] = False
  • Right[Player number of (Picked player))] = False
  • Down[Player number of (Picked player))] = False
  • Then - Unit - order Hero[Player number of (Picked player))] move to [(Position of Hero[Player number of (Picked player))])] offset by 70 towards (Facing of Hero[Player number of (Picked player))]
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = True
  • Left[Player number of (Picked player))] = False
  • Right[Player number of (Picked player))] = True
  • Down[Player number of (Picked player))] = False
  • Then - Unit - order Hero[Player number of (Picked player))] move to [(Position of Hero[Player number of (Picked player))])] offset by 70 towards (Facing of Hero[Player number of (Picked player))] + -5 degrees
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = True
  • Left[Player number of (Picked player))] = True
  • Right[Player number of (Picked player))] = False
  • Down[Player number of (Picked player))] = False
  • Then - Unit - order Hero[Player number of (Picked player))] move to [(Position of Hero[Player number of (Picked player))])] offset by 70 towards (Facing of Hero[Player number of (Picked player))] + 5 degrees
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = False
  • Left[Player number of (Picked player))] = False
  • Right[Player number of (Picked player))] = True
  • Down[Player number of (Picked player))] = False
  • Then - Unit - Make Hero[Player number of (Picked player))] face [(Facing angle of Hero[Player number of (Picked player))] + -5 degrees)] over 0.00 seconds
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = False
  • Left[Player number of (Picked player))] = True
  • Right[Player number of (Picked player))] = False
  • Down[Player number of (Picked player))] = False
  • Then - Unit - Make Hero[Player number of (Picked player))] face [(Facing angle of Hero[Player number of (Picked player))] + 5 degrees)] over 0.00 seconds
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = False
  • Left[Player number of (Picked player))] = False
  • Right[Player number of (Picked player))] = False
  • Down[Player number of (Picked player))] = True
  • Then - Unit - Move Hero[Player number of (Picked player))] instantly to [(Position of Hero[Player number of (Picked player))] offset by 5 towards [(Facing of Hero[Player number of (Picked player))] + 180 degrees)])]
  • Animation - Play Hero[Player number of (Picked player))]'s walk animation
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = False
  • Left[Player number of (Picked player))] = False
  • Right[Player number of (Picked player))] = True
  • Down[Player number of (Picked player))] = True
  • Then - Unit - Move Hero[Player number of (Picked player))] instantly to [(Position of Hero[Player number of (Picked player))] offset by 5 towards [(Facing of Hero[Player number of (Picked player))] + 180 degrees)])]
  • Unit - Make Hero[Player number of (Picked player))] face [(Facing angle of Hero[Player number of (Picked player))] + -5 degrees)] over 0.00 seconds
  • Animation - Play Hero[Player number of (Picked player))]'s walk animation
  • Else - If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[Player number of (Picked player))] = False
  • Left[Player number of (Picked player))] = True
  • Right[Player number of (Picked player))] = False
  • Down[Player number of (Picked player))] = True
  • Then - Unit - Move Hero[Player number of (Picked player))] instantly to [(Position of Hero[Player number of (Picked player))] offset by 5 towards [(Facing of Hero[Player number of (Picked player))] + 180 degrees)])]
  • Unit - Make Hero[Player number of (Picked player))] face [(Facing angle of Hero[Player number of (Picked player))] + 5 degrees)] over 0.00 seconds
  • Animation - Play Hero[Player number of (Picked player))]'s walk animation
  • Else -
  • Else -
Whoo! That was tough stuff! But now we have our movement complete. Now for the camera.

5: Create a real, non-array variable called LocZ
6: Create a point, non-array variable called Hero_Position

Add on to the Movement and Camera trigger afterwards:
  • Actions - -----camera-----
  • Player Group - Pick All players in (All players) and do actions:
  • Loop - Actions -
  • If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Hero[(Player number of (Picked player))] is alive = True
  • Then - Set Hero_Position[(Player number of (Picked player))] = Position of Hero[(Player number of (Picked player))]
  • Custom script: set udg_LocZ=GetLocationZ(udg_Hero_Position)
  • Camera - Lock camera target for (Picked player) to Hero[(Player number of (Picked player))] offset by ((25 x ((Cos(Facing of Hero[(Player number of (Picked player))], ((25 x ((Sin(Facing of Hero[(Player number of (Picked player))])))) using the unit's rotation
  • Camera - Set (Picked player)'s camera rotation to (Facing of Hero[(Player number of (Picked player))]) over 0.25 seconds
  • Camera - Set (Picked player)'s Height Offset to 85 + LocZ
  • Camera - Set (Picked player)'s Angle of attack to 340 (for now, we will change this later) over 0.50 seconds
  • Camera - Set (Picked player)'s Distance to target to 0 over 0.50 seconds
  • Camera - Set (Picked player)'s Far Z to 10000000 over 0.10 seconds
  • Custom script: call RemoveLocation (udg_Hero_Position)
Alright! Now we have a prototype working 1st person game. Camera will react with terrain, and move with your unit with the movement keys. The problem is that regular movement still applies, if you click and such. So, going more in depth, we add to the Camera and Movement trigger:
  • Actions - -----auto-stop aka no cheating!-----
  • Player Group - Pick All Players in (All Players) and do actions:
  • Loop - Actions -
  • If (All conditions are True) then do (Then actions) else do (Else actions):
  • If - Up[(Player number of (Picked Player))] = False
  • Down[(Player number of (Picked Player))] = False
  • Then - Unit - order Hero[(Player number of (Picked Player))] to stop
now there is no cheating! no moving with the mouse.

Difficult, but with 1st person cameras, that's the easiest it gets. For help on making scopes, shooting systems, and looking up and down, send me a private message.

Hope this helped!
- satient
 
Level 7
Joined
May 3, 2007
Messages
210
If you want to improve the boxes you can just copy the trigger in its interity-as-text and then post, wrap with TRIGGER tags. Try to fix it, because it's difficult to see what's going on without indentation. Here's an example of Melee Initalization:
With Tags:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
Without:
Melee Initialization
Events
Map initialization
Conditions
Actions
Melee Game - Use melee time of day (for all players)
Melee Game - Limit Heroes to 1 per Hero-type (for all players)
Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
Melee Game - Set starting resources (for all players)
Melee Game - Remove creeps and critters from used start locations (for all players)
Melee Game - Create starting units (for all players)
Melee Game - Run melee AI scripts (for computer players)
Melee Game - Enforce victory/defeat conditions (for all players)

You can't see the indentations in the post itself, but they're there. Here's one with //// were indendtations should be. Each / is a space.

Melee Initialization
////Events
////////Map initialization
////Conditions
////Actions
////////Melee Game - Use melee time of day (for all players)
////////Melee Game - Limit Heroes to 1 per Hero-type (for all players)
////////Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
////////Melee Game - Set starting resources (for all players)
////////Melee Game - Remove creeps and critters from used start locations (for all players)
////////Melee Game - Create starting units (for all players)
////////Melee Game - Run melee AI scripts (for computer players)
////////Melee Game - Enforce victory/defeat conditions (for all players)
 
Level 4
Joined
Jul 24, 2009
Messages
1,842
Nice, but way too complicated. I am not a baddas in triggers but i did this:
-copied some arrow key system
-made character with no model and shadow
-made really low, 360' camera with i think 30-5- offset
-locked camera to him
And that's it. Note that my system is useless for multiplayer, because the character is invisible.
 
Status
Not open for further replies.
Top