NAV16AP
3. jakso
lukuvuonna 2016-2017
SETTING UP
THE SCENE
This time
we are going to make a simple FPS game and this tutorial is for the player and
camera movement.
Start by
creating a 3D capsule. This can be done by right clicking the hierarchy and
choosing 3D object -> capsule. Make sure the transform for all the axis is
zero. Create a plane in same manner so that the player has a ground to walk on.
Rename the created objects as player and
ground. Renaming objects is important when your scene has lot of stuff in it.
Locating specific objects is easier when you have named them.
Then create
empty object by right clicking hierarchy and choosing create empty. Rename the
empty object as player controller and make the player object parented as child
to it. This is done by dragging the player and dropping it to the highlighted
player controller.
Now change
the y position of the player controller so that the capsule is not inside the
plane. Make another empty object and name it as camera position. Make it child
to the player object and drag it up and forward to where the camera would be.
Remember to position to the front of the player. The blue arrow indicates
forward movement.
Create
camera to the scene if you don’t have it there already. Make an empty game
object and rename it as camera controller. Parent it with the camera. Position
the camera controller in front of the player object. Create empty object as
child to the camera. Name it player look and position it further away in front
of the player. This will be the spot player looks at.
PLAYER
MOVEMENT
Now create
new component for the player object. Choose character controller from the
component list.
Create FSM named movement. Click the edit button to open
playmaker window.
In the first state you action set game object. Create came
object variable and choose it in the variable section. Then drag your player
object to the game object section. Make finished transition to new state.
Create
three actions for this state: get axis vector, controller simple move and look
at.
For the get
axis vector, you’ll need one vector3 variable. Use it in the store vector
section and drag you camera as the object in the relative to section.
In the
controller simple move action, choose your vector3 variable as move vector and
adjust the speed so that player walks in the speed you want it to.
In the last
look at action, choose your player look object as the target object.
CAMERA
Next create
fsm for the camera controller. This fsm will only have one state with action move
towards. Choose your camera position as the target object. Copy your z position
and remember to put checkmark in the ignore vertical. Use 20 as the max speed
and put 0 in the finish distance.
Lastly
create fsm for the camera. Use action called mouse look. Make it a little less
sensitive so that the camera won’t jump around.
Now go to edit -> project settings
-> input. Select mouse Y and put a checkmark in the invert box.
Ei kommentteja:
Lähetä kommentti