Home   Help Search Login Register  

Author Topic: Acceleration (Function)  (Read 1250 times)

0 Members and 1 Guest are viewing this topic.

Komuna

  • Guest
Acceleration (Function)
« on: 03 Jul 2003, 18:58:21 »
This function should return the acceleration value needed to slow down a certain vehicle, so that it would stop at a pre-defined position:

Code: [Select]
//Acc = preprocessfile "acc.sqf"
//[Vehicle,Position] call Acc

private ["_x","_y","_LZx","_LZy","_d","_V","_Vx","_Vy"]

_Vx = (velocity _this select 0) select 0;
_Vx = (velocity _this select 0) select 1;

_V = SQRT((_Vx^2)+(_Vy^2));

_x = (position _this select 0) select 0;
_y = (position _this select 0) select 1;

_LZx = (_this select 1) select 0;
_LZy = (_this select 1) select 1;

_d = SQRT(((_x-_LZx)^2)+((_y-_LZy)^2));


//Return acc value:

-((_V^2)/(2*_d))

------------------------------------------

This function was based on these equations:

V = Vo + a t
X = Xo + Vo t + 1/2 a t^2


*****
where:

V = final velocity
Vo = initial velocity
X = final position (LZ)
Xo = initail position
a = acceleration
t = time (duh!)

*******
remeber:

(X-Xo) = distance (d)
V = 0 (final velocity is null, so the vehicle stops at X)

********
-Vo = a t  <=>  -Vo / a = t

then

d = Vo*(-Vo/a) + 1/2 a*(-Vo/a)^2

which is the same as

-Vo^2 = 2*a*d

*********
(-Vo^2)/(2*d)=a is the conclusion I reach and which I use in the last line of the function.
--------------------------------------------

   As this function is called through a script, the returned value will be used in a looping process of deacceleration of a vehicle (a chopper, for example). I use setVelocity command to change the chopper's speed each 0.01 seconds (therefore, the acc value should be divided by 100). The script exits as the velocity becomes 0.


Note:

_vehicle setvelocity [_V*(Cos _dir),_V*(Sin _dir), 0]


where:

_V = SQRT(((_Vx-_acc)^2)+((_Vy-_acc)^2))

and

_dir = (_x-_LZx) atan2 (_y-_LZy)    [Not sure if it's right. My _dir equation does work, but i don't have it here :-[]

-----------------------------------------------------------------
   However, i've been very unlucky. The chopper does never stop where I want... It usualy travells more 50m or 100m away from the position until it stops :( :'(
   Is it a physics error? A maths error? A function error? Or is it another OFP bug?
« Last Edit: 03 Jul 2003, 19:32:12 by Komuna »

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Acceleration (Function)
« Reply #1 on: 03 Jul 2003, 19:20:45 »
:wow:

phisics  8)  ;D stil learnin but i got dis rules b4 ;D ;)

ma guess is OFP bug - or if u want it u can call it synTax bug ::) :P

all da this shud n _this

u forgot da _

e.g

Code: [Select]
_Vx = (velocity this select 0) select 0;
shud b

Code: [Select]
_Vx = (velocity _this select 0) select 0;

;)

LCD OUT

"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Komuna

  • Guest
Re:Acceleration (Function)
« Reply #2 on: 03 Jul 2003, 19:30:43 »
Greetings!!!

No. I didn't forgot the underscore. Maybe when i posted the topic, but the original sqf is (almost) perfect.

I'm sure, cuz I used hint format ["%1",_Acc] to check if any value was returned... And it did. ;)

Thanks anyway. Now, more sugestions?

Unnamed

  • Guest
Re:Acceleration (Function)
« Reply #3 on: 04 Jul 2003, 02:27:31 »
Hi,

If your giving it some kind of move order, for it to get to where you want it to stop.

Then try using DoStop, I got a heli to stop dead on the spot using:

Code: [Select]
Heli1 SetVelocity [0,0,0]
DoStop Heli1

BTW Komuna, I don't suppose you could help me with this? http://www.ofpec.com/yabbse/index.php?board=8;action=display;threadid=10821
« Last Edit: 04 Jul 2003, 02:36:50 by Unnamed »

deaddog

  • Guest
Re:Acceleration (Function)
« Reply #4 on: 04 Jul 2003, 03:34:12 »
Hey Komuna,

I'm not sure what the problem is with your script, but I have a similar script which I wrote a while back.  Take a look at this little demo mission to see what it does.  It uses basically the same formulas as your (the land.sqs script).  I didn't document it very well so there are a couple of items in there which I'm not sure why I did it that way :) It was a while back and the script was a little more complex.  I stripped it down for this.

BTW, this code:

_Vx = (velocity _this select 0) select 0;
_Vx = (velocity _this select 0) select 1;

_V = SQRT((_Vx^2)+(_Vy^2));

can be simplified like this:

_V=(speed _this select 0) * 0.277

speed returns the velocity in km/h and *0.277 converts it to meters/sec.

« Last Edit: 04 Jul 2003, 03:36:28 by deaddog »

Komuna

  • Guest
Re:Acceleration (Function)
« Reply #5 on: 04 Jul 2003, 19:28:50 »
Hi deaddog, hi Unnamed! ;)

#Unnamed:

Well, I see what you mean with "giving a move order", but that's what I was used to do when I worked with OFPv1.00... ;D And believe me, it's not very precise ::).

About the "Scary maths" thread - I'dd be very honoured to help you, but I've been working on the same thing: realistic artillery barrages; and I'm not very lucky. All I could give you is a little hint: define a position for the projectile every 0.001 seconds and, of course, use some physics :P ;)

Note: I made a not so realistic script which simulated a MRLS. It was very precise! If you want to take a look, PM me.

#deaddog

Ohhh... "land.sqs" too? I made a script (named "land.sqs" ;D) which purpose was stoping and landing a chopper with the "Acceleration" method. So, it means I'm not that original, huh? ::) :o

EhEh!

Okay, I'll take a look at your mission (yet I'm going to take a while as my motherboard was taken by mr.Chernobyl... :noo: ... Scary!).

About the simplification: Well, that's a nice trick, anyway I would still need the extended formula for this:

_V = SQRT(((_Vx-_acc)^2)+((_Vy-_acc)^2))

But I apreciate your help ;) :wave: I'm sure I'll use it.

OFPEC

Hmm... While I'm going to test deaddog's mission, this thread will be pending. Anyway, keep answering... :)

Unnamed

  • Guest
Re:Acceleration (Function)
« Reply #6 on: 04 Jul 2003, 20:23:13 »
Hi,

I must admit, I assumed your formula for slowing down vehicles was working. But not for helicopters?

I noticed that if you set a heli's velocity to zero, it will still continue in the direction it was heading. Initially I thought that was to do with the move order it had been given, which had not been completed.

But I guess, the pitch of the Heli could force it to move forward after you set velocity to 0?

Cheers, I will PM you if I can. I have kinematic equations comming out of my eyeballs, but none that can solve my problem in one pass.

Regards

Komuna

  • Guest
Re:Acceleration (Function)
« Reply #7 on: 26 Jul 2003, 19:23:34 »
Okay, I'll take a look at your mission (yet I'm going to take a while as my motherboard was taken by mr.Chernobyl... :noo: ... Scary!).

ZZZZZZZ... YAWN! :)
Well... Was just a power suply problem ;D ::) Eh!Eh!

So, deaddog, i've seen your mission and script and they look fine; yet I could notice some abnormal behaviour of the chopper when it deaccelerates... It seemed to forced, you know?
Therefore I found the answer for my accelereation function and updated the script... The result is a realistic chopper landing script. However, it still has some bugs, such as a strange chopper takeoff when I assign a certain unit as cargo, when the heli is landed on a roof... ???

So, guys, I'd like you to test the script, OK? Thanks!
Note: works fine on OFPv1.91; therefore, that version is recomended

deaddog

  • Guest
Re:Acceleration (Function)
« Reply #8 on: 27 Jul 2003, 00:00:44 »
Quote
yet I could notice some abnormal behaviour of the chopper when it deaccelerates... It seemed to forced, you know?

I agree with that.  I may be able to fix that by having it start slowing down sooner.  It needs to have the helo tilt backwards more to simulate it slowing itself down but I don't know how to do that.  :)

I'll look at your script.

*EDIT*

OK, I tried it out.  Yours doesn't have the same "forced" feel to it that mine does.  I think part of that may be due to the fact that you also have the vertical component in there.  My original landing script has that.  The one I sent you slows the helo down before descending which doesn't look realistic to begin with.

I also had to use the moveincargo command to board units, so the helo wouldn't want to land.  If the group is all AI, you could order them (individually) to move to the choppers position and then play an animation that looks like they are getting in.  Then do the "moveincargo".  Or at least do the moveincargo when they are very close to the helo.  This doesn't really work with a human controlled group too well.

Good job.
« Last Edit: 27 Jul 2003, 15:17:07 by deaddog »

Komuna

  • Guest
Re:Acceleration (Function)
« Reply #9 on: 03 Aug 2003, 19:24:07 »
AhUh! Yes, only through the "domove and playmove 'anim'" method the AI would avoid the "abnormal chopper behaviour".

Quote
Good job.

Hmm... Well, thanks, yet your script was a great influence.
For what I can see, your script's problem is that you set a default (de)acceleration value, you know? Besides, that thing with the '_p' variables, what is that used for? Indeed, it had some influence on the script, but for me, an average, maybe a bad scripter, the scripts should be very simple... you know, nothing with strngfe paramters and so ::). EhEh! ;)

Stay cool. Thanks for the help.