Jump to content
Sign in to follow this  
Nexus6

Attaching a camera to a vehicle. ver3 script by sn

Recommended Posts

Dear All, snYpir if your there. I want to incorporate the attach camera script in my camera sqs. Rather than use the whole script, I don't quite understand what I need to include. I have taken values and parameters directly form the SQS of snYpirs script but the camera is out to sea and does not target my plane. I have given the plane an id for the cam set target line.

script is at: www.ofpec.com/editors/resource_view.php?id=152

I just would like to know what bits I need and what I must include from the point of view of camera target.

Any help much appreciated.

Thanks very much

Share this post


Link to post
Share on other sites

It would help if you posted your camera script but I will try and help you.

The script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; concept by Turok_GMT, modified by snYpir,modified by [F-L]Sneaker 01.10.01 V3.0

; Sneaker added BLACK IN and BLACK OUT at the end of the script

; Sneaker added alive test of _unit in case of midair collision or enemy attack

; Sneaker added time limitation in seconds to prevent endless loop within game

; Sneaker doubled refresh rate of the camCommit command, to prevent lags at fast movements

; syntax:

; [<name of vehicle>, <name of unit to target>, <[xoffset,yoffset,zoffset]>,<relative to vehicle?>,<time limitation>] exec "vehiclecamV3.sqs"

; example: [heli, dilbert,[0,0,-10],false,300] exec "vehiclecam.sqs"

; get camera vehicle and target

_unit = _this select 0

_target = _this select 1

_timelimit = _this select 4

; define relative time at start of this script

_initialtime=daytime

; you can change the positional offsets for the camera (these are relative to the vehicle)

_camoffsetX = (_this select 2) select 0

_camoffsetY = (_this select 2) select 1

_camoffsetZ = (_this select 2) select 2

; do u want your offsets to be relative to the vehicle?

_camrelative = _this select 3

; clear the variable that will stop this script

vehiclecamstop = false

; create a camera

_cam = "camera" camcreate [0,0,0]

_cam cameraeffect ["internal", "back"]

#loop

; get actual time and calculate the time difference to _initialtime in seconds

_actualtime=daytime

_runtime=(_actualtime-_initialtime)*3600

; now create a loop to continuously update the cam's pos, so it appears to be attached to the vehicle

_newpos = getpos _unit

; set posn not relative to vehicle?

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

; set posn relative to vehicle

_cam camsettarget _unit

_cam camsetrelpos [_camoffsetX,_camoffsetY,_camoffsetZ]

#commit

; aim camera at target

_cam camcommit 0

_cam camsettarget _target

_cam camcommit 0

; insert a small update time to avoid anychance of any nasty infinity loop errors

~0.005

; perform an if test to see if _stop has been set to true or _uint has been killed: if not, do another lap of the loop

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

; the loop ends here when vehiclecamstop gets set to true by either a trigger or a waypoint's "on activation" field once loop had ended, kill the camera and return control to player

TitleCut ["","BLACK OUT",2]

vehiclecamstop = true

~2

_cam cameraeffect ["terminate", "back"]

camdestroy _cam

TitleCut ["","BLACK IN",2]

exit

The bits you will need:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = name of vehicle

_target = name of unit to target

_offset = [xoffset,yoffset,zoffset]

_timelimit = time limit

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = _this select 3

vehiclecamstop = false

#loop

_initialtime in seconds

_actualtime=daytime

_runtime=(_actualtime-_initialtime)*3600

_newpos = getpos _unit

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsettarget _unit

_cam camsetrelpos [_camoffsetX,_camoffsetY,_camoffsetZ]

#commit

_cam camcommit 0

_cam camsettarget _target

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

I haven't tested that so you may have to play around with it for a while smile_o.gif

RED

Share this post


Link to post
Share on other sites

Thanks Red, appreciate that. If still cant get it to work will post script.

Thanks gain.

Nexus6

Share this post


Link to post
Share on other sites

Just found one mistake, change this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_camrelative = _this select 3

To

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_camrelative = true or false

RED

Share this post


Link to post
Share on other sites

Not having much luck with getting the camera script to work in my cutscene. I attach my script. It must be a problem with the intial xyz offset and where I should place the co-ordinates. My object to target is named A6:

Any help appreciated

_unit = A6

_target = A6

_offset = [xoffset,yoffset,zoffset]

_timelimit = time limit

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true or false

vehiclecamstop = false

#loop

_initialtime in seconds

_actualtime=daytime

_runtime=(_actualtime-_initialtime)*3600

_newpos = getpos A6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsettarget A6

_cam camsetrelpos [7069.66,9323.03,2.00]

#commit

_cam camcommit 0

_cam camsettarget A6

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

Share this post


Link to post
Share on other sites

Some points,

1. Make _offset = [1,2,3] or any other numbers, play with it until it looks good.

2. _timelimit = 30, this will be 30 seconds following the target.

3. _camrelative = true, can also be false.

4. _initialtime in seconds, take this out of the script.

5. Make sure that your camera is called _cam.

The script should now look like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = A6

_target = A6

_offset = [1,2,3]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)*3600

_newpos = getpos A6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsettarget A6

_cam camsetrelpos [7069.66,9323.03,2.00]

#commit

_cam camcommit 0

_cam camsettarget A6

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

I will give it a test for you later.

RED

Share this post


Link to post
Share on other sites

Thanks very much, it working sweeter than a pale full of kittens.

One thing, how did you learn about scripting within OFP. Was it on the forums or did you read the Manual so to speak and trial and error. It just amazes me how all the excellent help is passed on from one to another.

Again, Thanks alot.

Share this post


Link to post
Share on other sites

I learnt by playing with scripts since the start of OFP, there are many good tutorials out there if you wish to learn though.

I prefer finding things out my self rather than reading tutorials, you could try looking at basic scripts and changing some of the code to see what it does.

RED

Share this post


Link to post
Share on other sites

Red, I was a bit early shouting the success. It doesnt actually work the camera is out to sea but way up high.

I have changed the name of the object to huey6 but the rest is the same. I am assuming I dont have to create a new camera for this section and that the camera in the previous scenes will work!

Here is the complete script

setacctime 0.4

0 fadesound 0

titlecut ["Welcome to NAM", "black in", 15]

_cam = "camera" camcreate [0,0,0]

_cam cameraeffect ["internal","back"]

;=== Napalm Opening

_cam camSetTarget [70488.81,86222.34,3269.88]

_cam camSetPos [9698.44,6888.14,11.65]

_cam camSetFOV 0.164

_cam camCommit 0

~40

;=== Troops

_cam camSetTarget ap

_cam camSetPos [11103.23,6742.57,1.99]

_cam camSetFOV 0.050

_cam camCommit 0

~10

;=== Boat

_cam camSetTarget pbr

_cam camSetPos [8798.84,4904.63,2.27]

_cam camSetFOV 0.057

_cam camCommit 0

~12

;=== Tanks

_cam camSetTarget [6282.03,6123.18,0.00]

_cam camSetPos [6342.76,6043.66,3.29]

_cam camSetFOV 0.250

_cam camCommit 0

~10

;=== huey

_unit = huey6

_cam camsettarget huey6

_offset = [1,2,3]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true or false

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +

_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsettarget huey6

_cam camsetrelpos [6265.78,9130.82,2.00]

#commit

_cam camcommit 0

_cam camsettarget huey6

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

Let me know if you got it to work,

Thanks again.

Share this post


Link to post
Share on other sites

One mistake you have made is:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_camrelative = true or false

Just make it true:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_camrelative = true

I will give it a run through later, I do not have the time at the moment.

RED

Share this post


Link to post
Share on other sites

Thanks Red, Cheers for that.

Nexus6

Share this post


Link to post
Share on other sites

Just looked at one aspect of the script, It could well be a problem with the XYZ co-ordinates that I give for the intial camera views. Set Rel Pos: Since the helo takes off and is the fourth scene of my opening sequence then for the vehicle huey the co-ord change. I thought the camera script would track the object all the time in the loop, but the time aspect may make that redundant as it is more then 30 secs before the 4th scene is called by the script.

Just one thing.

Cheers

Share this post


Link to post
Share on other sites

You just know BIS is going to come out with a simple command for this

movecamsetrelpos or something

Share this post


Link to post
Share on other sites

You got that right, probably ctrl c.

Share this post


Link to post
Share on other sites

Nexus6 if you are still having problems and wish to send me your mission today I will take a look at the camera script for you.

My email is graham_uk@btopenworld.com

RED

Share this post


Link to post
Share on other sites

Will do, will be around 6.30pm GMT. In work at present.

The camera script hasn't changed. It uses custom units SEB2 and a few others. Will send you the script, and the mission sqs.

Thanks again for your time.

Share this post


Link to post
Share on other sites

Hi All, using the excellent attach camera to a vehicle script it works very well now thanks to RED, basically I want the script to stop targeting one vehicle and begin targeting a second unit. I attach the script section from the camera attach script. The first unit is named huey6 the second I wish to target is huey7.

If anyone knows how to stop the first unit being targetted and move to the second I would be very greatful. I have tried the vehiclecamstop command set to true but it does not work in eithet a waypoint of trigger

All help appreciated.

Nexus6

;=== huey6

titlecut ["Helicopters form the mainstay of US Military support, Saving countless lives and

providing fire support in the dense jungle","black in", 5]

_unit = huey6

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = true

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +

_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsetTarget huey6

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit

_cam camcommit 0

_cam camsetTarget huey6

_cam camcommit 0

~0.005

;=== huey7

_unit = huey7

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey7

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +

_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsetTarget huey7

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit

_cam camcommit 0

_cam camsetTarget huey7

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;=== huey6

titlecut ["Helicopters form the mainstay of US Military support, Saving countless lives and

providing fire support in the dense jungle","black in", 5]

_unit = huey6

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsetTarget huey6

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit

_cam camcommit 0

_cam camsetTarget huey6

_cam camcommit 0

~0.005

;=== huey7

_unit = huey7

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

vehiclecamstop = false

#loop2

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey7

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit2"

_cam camsetTarget huey7

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit2

_cam camcommit 0

_cam camsetTarget huey7

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop2"

This should work now (not tested, again smile_o.gif) You will need to set vehiclecamstop to true in an external script, or just wait 30 seconds.

RED

Share this post


Link to post
Share on other sites

Thanks Red, will give it a try when I finish Work.

Cheers

Nexus6

Share this post


Link to post
Share on other sites

Hi, Red. Copied the script edit you posted in. It moves well to the next camera on the loop2. Only problem is it only stays on the original huey6 for half a second or so. It must be something to do with the time for the first camera or the spped at which loop 2 is actined.

Anyway, it is nearly there though. And again I do appreciate all the help you have given me with the cutscene I am creating.

Thanks

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;=== huey6

titlecut ["Helicopters form the mainstay of US Military support, Saving countless lives and

providing fire support in the dense jungle","black in", 5]

_unit = huey6

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsetTarget huey6

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit

_cam camcommit 0

_cam camsetTarget huey6

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

;=== huey7

_unit = huey7

_offset = [40,40,2]

_timelimit = 30

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop2

_actualtime=daytime

_runtime=(_actualtime-_initialtime)

_newpos = getpos huey7

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit2"

_cam camsetTarget huey7

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit2

_cam camcommit 0

_cam camsetTarget huey7

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop2"

Not being able to test this myself makes it quite hard to see how it is going to act, but this may work *fingers crossed*

RED

Share this post


Link to post
Share on other sites

Rapid Response, will give it a go when back at PC.

Cheers.

Share this post


Link to post
Share on other sites

Hi Red, The edit just will not target the next vehicle. I cannot stop the first camera, 30 secs go by but it stays on the first vehicle. When I set vehiclecamstop to true on the first vehicle within the script the first camera is skipped completely and it moves onto the second.

I cannot get it to stop from either a trigger or waypoint either.

Maybe its this line.

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

And this need some numerical values.

Again Thanks for the help.

Nexus6

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;=== huey6

titlecut ["Helicopters form the mainstay of US Military support, Saving countless lives and providing fire support in the dense jungle","black in", 5]

_unit = huey6

_offset = [40,40,2]

_timelimit = 0.5

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

#loop

_actualtime=daytime

_runtime=_runtime + 0.005

_newpos = getpos huey6

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) +_camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit"

_cam camsetTarget huey6

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit

_cam camcommit 0

_cam camsetTarget huey6

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop"

;=== huey7

_unit = huey7

_offset = [40,40,2]

_timelimit = 1

_initialtime=daytime

_camoffsetX = (_offset) select 0

_camoffsetY = (_offset) select 1

_camoffsetZ = (_offset) select 2

_camrelative = true

vehiclecamstop = false

_runtime = 0

#loop2

_actualtime=daytime

_runtime=_runtime + 0.005

_newpos = getpos huey7

? NOT(_camrelative) : _cam camsetpos [(_newpos select 0) + _camoffsetX, (_newpos select 1) + _camoffsetY, (_newpos select 2) + _camoffsetZ]; goto "commit2"

_cam camsetTarget huey7

_cam camsetrelpos [_camoffsetX, _camoffsetY, _camoffsetZ]

#commit2

_cam camcommit 0

_cam camsetTarget huey7

_cam camcommit 0

~0.005

? (NOT(vehiclecamstop) AND (alive _unit) AND (_runtime<_timelimit)): goto "loop2"

The timelimit variables are done in 10 seconds, for example

_timelimit = 1, this means that it will wait 10 seconds

_timelimit = 0.1, this means that it will wait 1 second

Sorry it took so long smile_o.gif

RED

Share this post


Link to post
Share on other sites

Sweet, it's just good that there are OFP editors like yourself out there who give the newbies a hand.

I will try, 2mor.

Nexus6

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×