Jump to content
Sign in to follow this  
-TheOne-

Attaching a camera to a vehicle

Recommended Posts

Well I'm a really noob scripter and I did a search on the forums but couldn't find anything and ofpec is down, so I was hoping that you could help.

So I was wondering how can you attach a camera to a vehicle so that it keeps moving with the vehicle? Probably a very simple answer, but heh, I'm a big noob when it comes to camera scripting...

Share this post


Link to post
Share on other sites

_vehicle SwitchCamera "EXTERNAL"

or this way:

useCamera = true

_c = "camera" camCreate getPos _vehicle

_c cameraEffect ["internal","back"]

_c camSetTarget _vehicle

_c camSetFov 0.7

_c camCommit 0

#loop

_c camSetRelPos [0, -20, 4]

_c camCommit 0

? useCamera : goto "loop"

_c cameraEffect ["terminate","back"]

camDestroy _c

...this will create a new camera, and then it will position it continuously 20 meters behind the vehicle, until the variable 'useCamera' becomes false (because you probably don't want the camera to be looking at the vehicle for eternity).

Just set the 'useCamera' to false from within some other script, or trigger, whatever suits you.

Share this post


Link to post
Share on other sites

It wont work for me. I want to do the following:

Camera moves to spot A, then to spot B and then moves to the plane, stays attached and then after a certain period of time end of loop and .... maybe moves to the next spot C

Quote[/b] ]

#loop

_camera cameraeffect ["internal", "back"]

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

goto "loop"

~20

Sorry, but I am an camera.sqs unexperienced lowbrainer and I got tired of experimenting! Once I do this I get a good loop, but how to end it, e.g. after a period of time? AND, most important, the camera doesnt move from spot B to the plane but directly changes to the view of the plane! Can I also stay attached to the plane for a few seconds and let the camera circle around it while it flies?

Share this post


Link to post
Share on other sites
Camera moves to spot A, then to spot B and then moves to the plane, stays attached and then after a certain period of time end of loop and .... maybe moves to the next spot C

Try this, it should work if you follow the comments

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

;create the camera at a location named spot0

_camera = "camera" camcreate [(getpos spot0 select 0), (getpos spot0 select 1), 3]

_camera cameraeffect ["internal", "back"]

;camera look at playername

_camera camsettarget playername

;camera move to spotA location in 6 seconds

_camera camSetPos [(getpos spotA select 0), (getpos spotA select 1), 3]

_camera camcommit 6

@camcommitted _camera

;camera move to spotB location in 5 seconds

_camera camSetPos [(getpos spotB select 0), (getpos spotB select 1), 3]

_camera camcommit 5

@camcommitted _camera

;camera move to the plane1 location in 6 seconds

; the 3 followind lines are to calculate where exactly the plane

; will be in the next 6 seconds

; make sure your plane flies at constant speed and in constant direction

; for the next 6 seconds

_xa=((velocity plane1 select 0)*6)

_ya=((velocity plane1 select 1)*6)

_za=((velocity plane1 select 2)*6)

_camera camSetPos [(getpos plane1 select 0)+_xa,(getpos plane1 select 1)+_ya,(getpos plane1 select 2)+_za]

_camera camsettarget plane1

_camera camcommit 6

@camcommitted _camera

;camera stay attached to plane during 15 seconds

;you must create a trigger activated by none

;at condition you must put startcount

;at On Activation you must put endplaneview=true

;at Countdown in min max mid put 15

startcount=true

#loop

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

? (endplaneview) : goto "nextstep"

goto "loop"

;once finished move the camera to spotC location in 5 seconds

#nextstep

_camera camsettarget playername

_camera camSetPos [(getpos spotC select 0), (getpos spotC select 1), 3]

_camera camcommit 5

@camcommitted _camera

;look again to the playername then destroy the camera after 5 seconds

; this way the player will be able to move again

~5

_camera cameraeffect ["terminate", "back"]

camdestroy _camera

exit

Share this post


Link to post
Share on other sites
Quote[/b] ]#loop

_camera cameraeffect ["internal", "back"]

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

goto "loop"

Once I do this I get a good loop, but how to end it, e.g. after a period of time?

You could do it like this without any external variable, trigger or script by using the _time function:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_delay = _time + 20.0; // how long the loop will run (20 seconds)

#loop

_camera cameraeffect ["internal", "back"]

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

?_time < _delay : goto "loop";

_time returns the time that has passed since the script was executed in seconds.

Share this post


Link to post
Share on other sites
Quote[/b] ]#loop

_camera cameraeffect ["internal", "back"]

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

goto "loop"

Once I do this I get a good loop, but how to end it, e.g. after a period of time?

You could do it like this without any external variable, trigger or script by using the _time function:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_delay = _time + 20.0; // how long the loop will run (20 seconds)

#loop

_camera cameraeffect ["internal", "back"]

_camera camsettarget plane1

_camera camsetrelpos [-2,10,3]

_camera camcommit 0

?_time < _delay : goto "loop";

_time returns the time that has passed since the script was executed in seconds.

I will give you feedback as soon as I have time to test it! Thank you very much indeed! thumbs-up.gif

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  

×