Script to Attach a Camera to a Vehicle (Version 2)
This script, originally by Turok and modified by snYpir, is an example of how to do 'fly bys' with a scripted cutscene. It can be used to attach a camera to any object in the game.
The example mission shows some possible ways to use vehiclecam.sqs. Use the radio to start the various instances of the cutscenes. Each cutscene is called via the following:
[name of vehicle,name of unit to target,[xoffset,yoffset,zoffset],relative to vehicle?] exec "vehiclecam.sqs"
name of vehicle is the name of the object that the camera will be attached to.
name of unit to target is the target object that the camera will follow.
[xoffset,yoffset,zoffset] is the camera positional offsets from the carrying vehicle in meters.
relative to vehicle is a true/false value. If true, your positional offset will be relative to the vehicle (as per camsetrelpos). If false, your positional offsets will be in normal x,y,z.
To explain this, imagine you have a vehicle going south. You have specified your offsets (in parameter 3) as [0,10,10] (remember this is X,Y,Z position). If the fourth parameter is true, the camera will be positioned relative to the direction the vehicle is travelling. ie, it will be 10m in front of the vehicle (10m south) and 10m above the ground. X,Y and Z are being measured with respect to the direction the vehicle is facing if the last parameter is 'true'.
If the last parameter was 'false', the camera would be positioned 10m to the north of the vehicle, and 10m above the ground (regardless of the direction the vehicle is facing).
An example would be:
[heli,dilbert,[0,0,-10],false] exec "vehiclecam.sqs"
This would call a cutscene where 'heli' is the carrying vehicle, 'dilbert' is the target unit, the camera will be 10 meters below 'heli' and we will not be using relative positional offsets.
In the example mission I used relative positional offsets for the tank to keep the camera central (even though the tank may change direction).
The example mission shows a number of different ways to start the cutscene, varying from triggers to waypoints to radio commands.
To stop the cutscene, the global variable vehiclecamstop must be set to false.
Attaching a camera to a vehicle is actually quite easy. If you open up vehiclecam.sqs, you can see the loop that simply keeps updating the position of the camera depending on the position of the vehicle. There is no reason why you couldn't copy this loop for use in your own cutscenes, whenever you want a camera to follow a moving object. Please post a message in the forum if u need help with this.
HINT: If you want the camera to simply target the 'carrying' vehicles, pass the same object name in as the 'target'. For example:
[heli,heli,[10,10,10],false] exec "vehiclecam.sqs"
Download the example mission or just the script.
Script to Attach a Camera to a Vehicle (Version 3)
By [F-L]Sneaker
This script, originally by Turok and modified by snYpir and
[F-L]Sneaker.
I have added BLACK IN and BLACK OUT at the end of the script
I have added alive test of _unit in case of midair collision or enemy attack
I have added time limitation in seconds to prevent endless loop within game
I have doubled the refresh rate of the camCommit command, to prevent lags at fast movements
Download the Example Mission