Home   Help Search Login Register  

Author Topic: Making setVelocity relative to the vehicle's direction.  (Read 851 times)

0 Members and 1 Guest are viewing this topic.

Offline Nemesis6

  • Members
  • *
Asking plainly, is this possible?
I am actually flying into a star... this is incredible!

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Making setVelocity relative to the vehicle's direction.
« Reply #1 on: 27 Oct 2004, 02:11:54 »
Yeap... sure is.

If you want the velocity of your object to be the same as your vehicle, it's as simple as:

object setvelocity (velocity vehicle)

If you're looking to set the velocity relative, but not the same that's possible too...
However it's a tad more complicated ;)
« Last Edit: 27 Oct 2004, 02:13:00 by Sui »

Offline Nemesis6

  • Members
  • *
Re:Making setVelocity relative to the vehicle's direction.
« Reply #2 on: 27 Oct 2004, 09:14:20 »
Well, I know how to do that, but I'm trying to, well, for starters, make a tank slide left. So I tried this - _vehicle setVelocity [(velocity _vehicle select 0) - 0,velocity _vehicle select 1,velocity _vehicle select 2] but it still goes relative to the map. Here's the deal - I'm trying to make the MGs eject the actual bullet model from OFP - FxCartridge, but I need the bullet's ejection velocity to be relative to the MGs right side.
I am actually flying into a star... this is incredible!

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Making setVelocity relative to the vehicle's direction.
« Reply #3 on: 27 Oct 2004, 11:09:21 »
You'll need to use a little trigonometry.  (Sin, cos, tan and all that lot.)   If you're a bit rusty or have never encountered it there is an OFP trig guide in the Ed Depot somewhere.   You can use the getDir command to discover the direction a vehicle is facing, and the speed command if you want it's speed.    Or just grab the velocity directly as Sui suggested.
Plenty of reviewed ArmA missions for you to play

Offline Nemesis6

  • Members
  • *
Re:Making setVelocity relative to the vehicle's direction.
« Reply #4 on: 27 Oct 2004, 17:18:22 »
I know the getdir command... I still can't get it to work, of course I can get it to face the players direction... [0,0,0] The bold zero is the one I need to be relative to the the player. Anyway, please, do tell if you have some help.
I am actually flying into a star... this is incredible!

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Making setVelocity relative to the vehicle's direction.
« Reply #5 on: 30 Oct 2004, 01:45:37 »
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 :P
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 Explaination

The SetVelocity Command
The 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 Trigonometry

Let'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 trig

The 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 :P

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 ;)