Results 1 to 8 of 8

Thread: Attaching a camera to a vehicle

  1. #1
    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...
    Now Known as Mehman

  2. #2
    Master Gunnery Sergeant 5133p39's Avatar
    Join Date
    Feb 2 2004
    Location
    Czech Republic
    Posts
    1,383
    _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.
    MSI P55-GD65 | Core i5 750 @ 2.67GHz | 4GB DDR3 | ATI HD 5970 (Asus EAH5970​/G​/2DIS​/2GD5) | OCZ Revo 120GB PCIe SSD | 2x OCZ Vertex 4 120GB |
    Windows 7 64bit Home Premium | Catalysts 13.1 | ArmA2 OA 1.62.0.101480 (beta) +BAF +PMC +ACR | ArmA2 1.11.0.86734 | ArmA 1.18.0.5281 | OFP 1.0.0.96

    Be smart, use Sprocket!

  3. #3
    It worked, thank you.

  4. #4
    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 Originally Posted by [b
    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?



    ..................

    Watch also Part 2 and Part 3 .................................................. ............................*Social Group for ArmA Cineasts, join now!

  5. #5
    Quote Originally Posted by (Albert Schweizer @ July 10 2006,23:38)
    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 = &#34;camera&#34; camcreate &#91;&#40;getpos spot0 select 0&#41;, &#40;getpos spot0 select 1&#41;, 3&#93;
    _camera cameraeffect &#91;&#34;internal&#34;, &#34;back&#34;&#93;

    ;camera look at playername
    _camera camsettarget playername

    ;camera move to spotA location in 6 seconds
    _camera camSetPos &#91;&#40;getpos spotA select 0&#41;, &#40;getpos spotA select 1&#41;, 3&#93;
    _camera camcommit 6
    @camcommitted _camera

    ;camera move to spotB location in 5 seconds
    _camera camSetPos &#91;&#40;getpos spotB select 0&#41;, &#40;getpos spotB select 1&#41;, 3&#93;
    _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=&#40;&#40;velocity plane1 select 0&#41;*6&#41;
    _ya=&#40;&#40;velocity plane1 select 1&#41;*6&#41;
    _za=&#40;&#40;velocity plane1 select 2&#41;*6&#41;

    _camera camSetPos &#91;&#40;getpos plane1 select 0&#41;+_xa,&#40;getpos plane1 select 1&#41;+_ya,&#40;getpos plane1 select 2&#41;+_za&#93;
    _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 &#91;-2,10,3&#93;
    _camera camcommit 0
    ? &#40;endplaneview&#41; &#58; goto &#34;nextstep&#34;
    goto &#34;loop&#34;

    ;once finished move the camera to spotC location in 5 seconds
    #nextstep
    _camera camsettarget playername
    _camera camSetPos &#91;&#40;getpos spotC select 0&#41;, &#40;getpos spotC select 1&#41;, 3&#93;
    _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 &#91;&#34;terminate&#34;, &#34;back&#34;&#93;
    camdestroy _camera
    exit[/QUOTE]




  6. #6
    thank you very very much. Luckily I even see the logic in your suggestion&#33;

    I will try it out as soon as I get out of office&#33;


  7. #7
    Quote Originally Posted by [b
    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 &#40;20 seconds&#41;
    #loop
    _camera cameraeffect &#91;&#34;internal&#34;, &#34;back&#34;&#93;
    _camera camsettarget plane1
    _camera camsetrelpos &#91;-2,10,3&#93;
    _camera camcommit 0
    ?_time &#60; _delay &#58; goto &#34;loop&#34;;[/QUOTE]
    _time returns the time that has passed since the script was executed in seconds.

  8. #8
    Quote Originally Posted by (Metal Heart @ July 11 2006,10:52)
    Quote Originally Posted by [b
    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 &#40;20 seconds&#41;
    #loop
    _camera cameraeffect &#91;&#34;internal&#34;, &#34;back&#34;&#93;
    _camera camsettarget plane1
    _camera camsetrelpos &#91;-2,10,3&#93;
    _camera camcommit 0
    ?_time &#60; _delay &#58; goto &#34;loop&#34;;
    _time returns the time that has passed since the script was executed in seconds.[/QUOTE]
    I will give you feedback as soon as I have time to test it&#33; Thank you very much indeed&#33;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •