Jump to content
gc8

Moving objects via script

Recommended Posts

Hi

I'm doing some scripting to make object move where I want it via script. But the problem I encountered was that if I use setVectorUp or setVectorDir that hinders the object's movement and I don't know why.

Alone setVelocity call would work but I need to call those two functions as well.

 

The object I'm trying to move is car (hunter)

 

Any ideas how to fix are welcome

 

addMissionEventHandler ["EachFrame",
{

_vup = vectorUp testcar;

_d = vectorDir testcar;

if(false) then // If true the movement will slow down
{
testcar setVectorUp _vup;
testcar setVectorDir _d;
};

testcar setVelocity [10,0,0];
 
}];

 

Share this post


Link to post
Share on other sites

You should use setVelocityTransformation

 

example:

addMissionEventHandler ["eachFrame", {
testcar setVelocityTransformation [getPosASLVisual testcar, getPosASLVisual testcar vectorAdd [10,0,0],[10,0,0],[10,0,0],vectorDirVisual testcar, vectorDirVisual testcar, vectorUpVisual testcar, vectorUpVisual testcar, 0.1]
}];

 

Last figure is a kind of multiplier here (0 to 1).

  • Like 3
  • Thanks 2

Share this post


Link to post
Share on other sites

I'm sure pierremgi's suggestion will work.  But you can also use setVelocityModelSpace.  In my Razing Cane mission, I have an AI driven car that I want to force to accelerate quickly to 100km.  In an EachFrame eventhandler, I have the following code.  This incrementally increases forward motion (y velocity) smoothly until desired cruise speed reached.  The condition "and getposatl _veh select 2 < .1" prevents this code from making vehicle fly if it bounces off the ground.

            if (speed _veh < 100 and getposatl _veh select 2 < .1) then
            {
                _veh setVelocityModelSpace [0, (velocityModelSpace _veh select 1)+.06, 0];  // accelerate incrementally to reach cruise speed
            };

 

Share this post


Link to post
Share on other sites
Quote

if(false) then

 

What is this evaluating? I don't think your setVectorUp etc commands will every be run in this setup.

Share this post


Link to post
Share on other sites
10 minutes ago, Ryko said:

 

What is this evaluating? I don't think your setVectorUp etc commands will every be run in this setup.

Imho, it's was just an example in which you had to set false then true to see the difference in preview.

Share this post


Link to post
Share on other sites
13 hours ago, pierremgi said:

Imho, it's was just an example in which you had to set false then true to see the difference in preview.

 

Yes

Share this post


Link to post
Share on other sites

i don't know if I'm doing this right because it's not working. I was previously using setVelocity, setVectorDir and setVectorUp to move a helo but the movement was bit choppy. So I tried to smoothen it by using setVelocityTransformation  but my code below doesn't really work as the helo travels to wrong direction...

 

This is my code (_velvec, _vecDir, _vecUp are calculated elsewhere, these are the new values I want to apply):

 

_helo setVelocityTransformation 
[
    getPosASL _helo,
    getPosASL _helo,  // What to put here?
    velocity _helo,
    _velvec,
    vectorDir _helo,
     _vecDir,
    vectorUp _helo,
     _vecUp,
    0.5
];

 

Also I don't know what to put as parameter for the second position?

 

Share this post


Link to post
Share on other sites
1 hour ago, killzone_kid said:

 

destination

 

I put there destination and the helo crashes instantly to ground and explodes

Share this post


Link to post
Share on other sites

Thanks killzone_kid I will look into the new documentation but I have to ask one important question. Am I using the right command when I was previously using setVelocity, setVectorDir and setVectorUp and now want to archive same effect with setVelocityTransformation?

Share this post


Link to post
Share on other sites
Just now, killzone_kid said:

Different commands for different things, not sure what you are trying to do so ¯\_(ツ)_/¯

 

ok. It does seems to me as well that I cant switch the commands. I'm trying to make helo land which I got working but it's movement is bit choppy 

Share this post


Link to post
Share on other sites

BIKI: For continuous movement this command should be executed each frame while changing interval value

That probably the most difficult to understand. "Interval" here is not a simple figure (fixed part of the total value). This is a variable, sum of delay from start 0 to end 1. The BIKI gives an example using moveTime but it's not evident to catch the idea.

The help and comment could gain explaining how to obtain the same cinematic than the plane. I failed.

If the challenge is to obtain something visually credible for a plane, that's a lot of work to match, on each frame, a position with a "correct" attitude of the plane (not saying the need to end that animation).

 

Share this post


Link to post
Share on other sites

@pierremgi It's a nice command actually. I got it working on my test mission but couldn't use any of my old code with it. I also noticed it's possible to move helo through terrain with that command, which is bad of course.

Share this post


Link to post
Share on other sites
1 hour ago, gc8 said:

it's possible to move helo through terrain with that command

Yeah it basically grabs object and as long as you execute it each frame it doesn't let it go 

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

This is a variable, sum of delay from start 0 to end 1

Think of it as animation slider. in fact I think you can even hook ingame slider to it to animate your interval manually

 

 

  • Like 2

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

×