Ahh... ok. This is going to be a tad more complicated then
To eject a cartridge at 90 degrees from the vehicle, you'd use this:
object setvelocity [(velocity
vehicle select 0) + (sin (getdir
vehicle + 90) * 1), (velocity
vehicle select 1) + (cos (getdir
vehicle + 90) * 1), (velocity
vehicle select 2) - 0.5]
Ha! And you thought it was going to be complicated?! ;D
Right, lets take this bit by bit.
Forgive me if I sound like I assume you're stupid
I mean no offence, it just helps my explaination if I start from the ground up. This way I won't omit anything due to assumptions of how much anyone knows in advance...
The ExplainationThe SetVelocity CommandThe syntax goes like this:
object setvelocity [
x, y, z ]
Where
x is the East-West co-ord,
y is the North-South co-ord, and
z is the up down co-ord.
So this is relative to the
map, and true north. Not to the velocity of the object itself.
The Crazy TrigonometryLet's analyse the first part of that crazy line of code up there:
(velocity
vehicle select 0) + (sin (getdir
vehicle +
90) *
1)
This is the value for
x in our setvelocity command.
All it does is take the x velocity of
vehicle, and add
1 m/s to it.
It adds it
90 degrees to the direction the vehicle is facing.
So by changing those two numbers to what ever value you need, you can make your object move relative to your vehicle.
The next section of the crazy trigThe second bit:
(velocity
vehicle select
1) + (
cos (getdir
vehicle + 90) * 1)
Is almost exactly the same. Apart from the two parts I've underlined. If you don't keep the values the same, you'll get some strange results depending on what direction
vehicle is facing... I don't really recommend it
So in summary...The setvelocity command:
object setvelocity [
x,
y,
z ]
The setvelocity with trig:
object setvelocity [
(velocity vehicle select 0) + (sin (getdir vehicle + 90) * 1),
(velocity vehicle select 1) + (cos (getdir vehicle + 90) * 1),
(velocity vehicle select 2) - 0.5 ]
To change the direction in bearings relative to
vehicle, change the
90. To change the linear speed (in m/s), change the
1.
...(velocity
vehicle select 0) + (sin (getdir
vehicle +
90) *
1)...
Anyway, hopefully that explanation wasn't too bad
It can be a bit hard to come to grips with at first, but once you understand it, that can be used for damn near everything in OFP. Getpos/setpos calls, setvelocity, and most especially camera scripting