Pages

Wednesday, November 20, 2013

[TUT] Camera control

My understanding about camera is restricted, i will show in this tutorial what i know about cameras in GTA IV.

Download the supply code employed here (mirror)

Initial of all we have direct access to the actual active camera utilizing the following object:

Game.CurrentCamera

With this object we can obtain beneficial information about actual active camera:



Other way to receive access to actual game camera is utilizing this object:

Game.DefaultCamera

The issue with this object is that it disappear (= absolutely nothing) when an ped is set as targeted by player when player is unarmed, so, if you want use this camera be cautious and make the Exists(Game.DefaultCamera) verify prior to use.

GET_GAME_CAM
This native strategy will return the game camera, really valuable when we need to have to discover the actual game camera doesn't matter if we have a gun or not:




Creating a camera

To produce a camera we want an object of type camera and we want to produce a new instance of it:



Now to see the view of this camera we need to have to Activate it:


To demonstrate some camera handle let's produce an free camera with keyboard handle, when i press move keys the camera will move forward and backward, when i press + and - camera will zoom in and out and when i press left/correct/up/down camera will alter direction:


Fundamentally what i am changing right here is Position, Rotation and FOV.

An fascinating approach to use is the LookAt, we can set the camera to appear at a Ped, Object, Vehicle or a single position, when we set this we can not manage the camera direction or rotation any longer:


To get control more than Path and Rotation again we need to contact UNPOINT_CAM method:


Yet another cool strategy to use is the SET_CAM_SHAKE:


Very first param is the camera, we can shake the game camera also but ahead of we need to contact CAM_Approach and specify game.default camera as the param.

Second param appears to be the level of movement, from 1 to 8

Third param is the time in milliseconds, -1 will result in a shake of approximated 1 second

This is what you need to do to shake the game default camera:




Attaching a camera

We can attach camera employing the following strategies:

ATTACH_CAM_TO_OBJECT
ATTACH_CAM_TO_PED
ATTACH_CAM_TO_Car
ATTACH_CAM_TO_VIEWPORT

Soon after attaching the camera we can set the offset from the attach point employing this strategy:

SET_CAM_ATTACH_OFFSET

To make the attach be relative to the object we need to call this strategy:

SET_CAM_ATTACH_OFFSET_IS_RELATIVE

To remove the attach we use UNATTACH_CAM

Let's make an example of this attach, let's attach the camera to player existing automobile, if player are not in a vehicle let's attach the camera to him:


Now, in a tick we require to set the camera direction or rotation:



With some coding and imagination you can very easily produce a fundamental very first particular person camera.
[TUT] Camera control
9out of 10 based on 10 ratings. 9 user reviews.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.