Jump to content
Sign in to follow this  
CptBBQ

relative acceleration

Recommended Posts

Hi everyone,

I´ve ran into a problem I just can´t explain to myself. I´ve taken this code from the biki:

_vel = velocity _vehicle;

_dir = direction _vehicle;

_speed = 80;

_vehicle setVelocity [(sin _dir*_speed),(cos _dir*_speed),(_vel select 2)];

It should accelerate a vehicle in the direction it´s already heading towards.

I just changed it a little so _speed isn´t added to the velocity but velocity is set to _speed.

I need to use this script on two different vehicles:

Old_moto_TK_Civ_EP1 and S1203_TK_CIV_EP1

With the motorcycle everything works as intended but the car just makes a small leap, and then it stops abruptly.

I´m completely baffled about this because the only difference in the code is the vehicle classname.

Any ideas?

Thanks in advance,

CptBBQ

Share this post


Link to post
Share on other sites

CptBBQ what you do ther is only to add in a little Push. what i mean you only increse the speed once.

what you need is a kind of loop

example

while {true} do
{
   if (TURBO_KEY) then
   {
       _vel = velocity _vehicle;
       _dir = direction _vehicle;
      _speed = 1;
      _vehicle setVelocity [(sin _dir*_speed),(cos _dir*_speed),(_vel select 2)]; 
   };
   sleep 0.1;
};

where you probealy want TURBO_KEY set by a displayevent handler on a spesific key,

press down on Lsift sets TURBO_KEY as true

and releasing the button sets TURBO_KEY as false

Share this post


Link to post
Share on other sites

Thanks guys!

Your answers explain why the motorcycle takes off like a rocket while the heavier car won´t move much at all. So, I´ll experiment with a loop and see what happens.

Maybe there´s a better way to achieve what I intended. So I´ll explain a little..

The vehicles will be driven by civilian AI´s which, at some point in a mission, will head towards the closest blufor troops and blow them self up when they are close enough.

For the movement I used the 'doMove' command. This worked fine for pedestrians, but AI in a vehicle will not come closer than 20-30m to it´s target. So at that point I let kick in the acceleration, which was enough to nudge the motorcycle towards it´s target.

As I´ve just learned, a much heavier vehicle will take a whole different kinetic impulse to reach it´s target. But of course, I want to control both (and maybe even more) vehicles with the same script.

So, maybe the doMove command is more of a problem than the relative acceleration code.

I´m still learning and always thankful for a insight on how others would solve the same problems.

Cheers,

CptBBQ

EDIT: Executing the code within a loop results in a very choppy, "laggy" movement. Looks like the car goes right back to its original velocity after every loop.

I think I need to take a different approach...

Edited by CptBBQ

Share this post


Link to post
Share on other sites

CptBBQ

if ist laggy/choppy adjust the sleep.

i tested this on a red civilian car on utes,. from star to end.

had 290 Km/H at the end of the runway without any lagg/choppyness

_vehicle = _this;
while {true} do
{
   if (TURBO_KEY) then
   {
       _vel = velocity _vehicle;
       _dir = direction _vehicle;
      _speed = 1;
      _vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)];
   };
   sleep 0.01;
};

i just used 2 tradio triggers to set TURBO_KEY true/false

PS. Make the SetVelocity the same way as in the biki example. dont take out part of it.

Share this post


Link to post
Share on other sites

Thanks nuxil!

The "sleep 0.01" did the trick. I´ll just have to adjust _speed depending on the vehicle. But that´ll be just a little trial and error.

:bounce3:

Cheers,

Bbq

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×