Home   Help Search Login Register  

Author Topic: I need some help with a flybycam script  (Read 1034 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
I need some help with a flybycam script
« on: 30 Nov 2004, 08:35:27 »
Here is my goal : I try to write a automatic flybycam script for planes :

1 - setpos a gamelogic in front of the plane,
2 - put the camera at the position of that gamelogic,
3 - camtarget the plane.

Now the problem is :
How can I detect the plane has passed the logic so it can be setpossed again in front of the plane and start the whole thing over in loop?


I thought this could work

@_lg distance _plane > 300
; plane is far away behind my gamelogic

@_lg distance _plane < 100
; _plane is close now

@_lg distance _plane > 300
; Plane is far away in front of my gamelogic, it should be passed by now...

 :P

WRONG!

When the plane starts 250 m high when it's far away and 100m high when it's close, distance is more then 100m so that second condition will never be met... * BUM* Distance is also measured in Z -coords

So, Is there some formula or function I can use combined with the speed of the vehicle?

Here is the script :

Quote
_camid = _this select 0
_unit = _this select 1

flybycam = true

_lg = "logic" camcreate [0,0,0]

#flybycalc
_spd = Speed _unit
_dist = (_spd * 1.1 + random 10)
_xpos = (getpos _unit select 0)+(sin (getdir _unit)*_dist)
_ypos = (getpos _unit select 1)+(cos (getdir _unit)*_dist)
_lg setpos [_xpos,_ypos,(getpos _unit select 2)]

_camid camsetpos getpos _lg
_camid camsettarget _unit
_camid camcommit 0

_wait = _Spd / 60
~_wait
?flybycam && alive _unit : goto "flybycalc"
deletevehicle _lg
exit

You have to run this in a camera script:

example

[_camera,Plane] exec "flybycam.sqs"
and flybycam = false will exit the script

The _wait calculation is just temporary, it works fine when the speed of the plane is around 300- 400 km/h, but when the speed is lower the camera switches to fast imo.

Any suggestions how I can do this so it always works good in every situation (maybe also for cars, tanks,ect...) ?

If you are interested in this, dl the testdemo mission I'v made, no addons needed.Use your radio Alpha to start the demo.




 



 
« Last Edit: 30 Nov 2004, 09:49:45 by Blanco »
Search or search or search before you ask.

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:I need some help with a flybycam script
« Reply #1 on: 30 Nov 2004, 09:28:56 »
yeah, two things:

A) don't use distance in MP, since distance only works between local units.  Use old-fashioned trig.
B) instead of measuring absolute distance, measure the change in distance between each iteration.  As long as that is negative, the object is coming towards you. When it's positive, it's moving away.
Dinger/Cfit

Offline Blanco

  • Former Staff
  • ****
Re:I need some help with a flybycam script
« Reply #2 on: 02 Dec 2004, 06:14:18 »
Thx,

I've tried it that way but it was still not reliable in all situations.
I gave it another try with this :

Quote
; flybycamBeta by Blanco


_camid = _this select 0
_unit = _this select 1

_distanceSqr = {(((getpos (_this select 0)) select 0)-((getpos (_this select 1)) select 0))^2 + (((getpos (_this select 0)) select 1)-((getpos (_this select 1)) select 1))^2}

flybycam = true
flycamdone = -1

_lg = "logic" camcreate [0,0,0]

#flybycalc
_spd = Speed _unit
_dist = _spd * 1.1

_randomX = 50 - random 100
_randomZ = 20 - random 40

_xpos = (getpos _unit select 0)+(sin (getdir _unit ) *_dist)
_ypos = (getpos _unit select 1)+(cos (getdir _unit)*_dist)
_lg setpos [((_Xpos)+ _randomX),_Ypos,(getpos _unit select 2)+ _randomZ]


#calc
_camid camsetpos getpos _lg
_camid camsettarget _unit
_camid camsetfov 0.7
_camid camcommit 0


_dissqr = [_lg,_unit] call _distancesqr

_hdis = sqrt (_dissqr)
_rdis = _dist - (_dist * 30/100)
;player globalchat format ["%1     %2",_hdis,_rdis]

~0.1
?!flybycam : goto "destroy"
?_hdis < _rdis  : goto "preparezoom"
goto "calc"


#preparezoom
_spd = speed _unit
?_spd < 10 : goto "skip"
_wait = 7
#zoom
?!flybycam : goto "destroy"
~2
_camid camsetfov 0.2
_camid camcommit _wait
#skip
~_wait
goto "flybycalc"

#destroy
Flycamdone = 1
deletevehicle _lg
exit

the _distanceSqr  line on top of the script should calculate the 2D distance (I'm still not sure about that), I store the result in the _hdis variable. Then I calculate 30% of the absolute distance (_rdis) between camera and plane, so the loop exits when the plane has traveled 30% of the absolute distance. I did not choose 80% or more because there were some problems with choppers when they took sharp turns.
ok, when _hdis < _rdis the loop exits and the script jumps to the zooming part after a short delay.

I've tested this now for two days and it works very well, except for choppers when they're flying backwards...
I know why : _dist depends on the vehicle's speed, so when it's negative the logic is created behind the vehicle...also not reliable when the vehicle is moving really slow, I have to fix that part.
The same problem with landvehicles...I think I have to write another script for that (drivebycam  :) )

You have to run this in your camerascript :

First create your cam :

Quote
_camera = "camera" camcreate [0,0,0]
_camera cameraeffect ["internal","back"]

then run the script :

Quote
[<camera id>,<vehiclename>] exec "flybycam.sqs"

to exit the script you'll need these two lines :

Quote
flybycam = false
@flycamdone == 1

The first one, the bolean; is needed to exit the loops, the second one is needed so the script waits until the zooming part is ended or to prevent that two camera's are running at the same time.






 
 

« Last Edit: 02 Dec 2004, 15:36:42 by Blanco »
Search or search or search before you ask.

Offline Blanco

  • Former Staff
  • ****
Re:I need some help with a flybycam script
« Reply #3 on: 03 Dec 2004, 01:17:28 »
Forget the previous script , I got a much better one now. :)
Works perfect for planes, I just have to tweak some values for landvehicles...

I will post it soon in the betascript board.
Search or search or search before you ask.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:I need some help with a flybycam script
« Reply #4 on: 03 Dec 2004, 17:54:20 »
Maybe a little late, but I just found this forum topic that has quite a bit of useful information on several topics, one that details how to use the CalcRelPos.sqf for camera scripting. Take a look here if you still need some tips.


                                                    Wadmann
Check out my Camouflage Collection! New items added 31 July 2005.