Jump to content
Sign in to follow this  
sudslv

Flip nearby vehicle.

Recommended Posts

Hi im making a Vehicle flip script which is executed in GUI on button click.

I cant figure out how to "locate" nearby vehicles.

flip script:

// Flip vehicle 0.5m above ground.
_veh setpos [getpos _veh select 0, getpos _veh select 1, 0.5];

Share this post


Link to post
Share on other sites

The command you're searching for is nearObjects (or possibly nearestObjects for a sorted list).

It returns an array with all the objects of the type and the radius you specified.

_cars = nearestObjects [player, ["Car", "Motorcycle"], 85];

This would find any cars and motorcycles within a distance of 85 meters around the player and put it into _cars as an array with the nearest object as the first element.

Share this post


Link to post
Share on other sites

// Locate nearby vehicle.
_veh = nearestobjects [player,["car"],500];  
// Flip vehicle 0.5m above ground.
_veh setPosASL [ getPosASL _veh select 0, (getPosASL _veh select 1) + 2,
getPosASL _veh select 2]; 
hint "you flipped car";

doesnt work for some reason (when i test with player, it works)

btw: im trying this with "wasteland" spawned cars.

Edited by sudslv

Share this post


Link to post
Share on other sites
The command you're searching for is nearObjects (or possibly nearestObjects for a sorted list).

It returns an array with all the objects of the type and the radius you specified.

_cars = nearestObjects [player, ["Car", "Motorcycle"], 85];

This would find any cars and motorcycles within a distance of 85 meters around the player and put it into _cars as an array with the nearest object as the first element.

// Locate nearby vehicle.
_veh = nearestobjects [player,["car"],500];  
// Flip vehicle 0.5m above ground.
{
   _newPos = getPosASL _x;                          // get the position of the current vehicle in the array
   _newPos set [2, (_formerPos select 2)+0.5]; // add 0.5m to Z-Coord

   _x setPosASL _newPos;                             // set the new position
} forEach _veh;

hint "you flipped car";

_x is a magic variable which references the element in the current cycle of the array :)

Share this post


Link to post
Share on other sites
// Locate nearby vehicle.
_veh = nearestobjects [player,["car"],10];  
// Flip vehicle 0.5m above ground.
{
   _newPos = getPosASL _x;                          // get the position of the current vehicle in the array
   _newPos set [position this select 0, position this select 1, +1];

   _x setPosASL _newPos;                             // set the new position
} forEach _veh;

hint "you flipped car"; 

Edited by sudslv

Share this post


Link to post
Share on other sites

today i realised that it doesnt solve my problem and saw this. can you point out where im wrong?:

// Locate nearby vehicle.
_veh = nearestobjects [player,["car"],10];  
// Flip vehicle 0.5m above ground.
{
   _newPos = getPosASL _x;                          // get the position of the current vehicle in the array
   _newPos set [position this select 0, position this select 1, +1];
   _veh setVectorUp [0,1,0];

   _x setPosASL _newPos;                             // set the new position
} forEach _veh;

hint "You flipped car";

i would like the car to move ~1m to some side and flip it.

Edited by sudslv

Share this post


Link to post
Share on other sites

WHoops, there was a rogue variable name in there... xD

_veh = nearestobjects [player,["car"],10];  
// Flip vehicle 0.5m above ground.
{
   _newPos = getPosASL _x;                          // get the position of the current vehicle in the array
   _newPos set [2, (_newPos select 2)+1];   // add 1m to Z-Coord

   _x setPosASL _newPos;                             // set the new position
} forEach _veh;

hint "you flipped car";

You don't need to use setVectorUp, setPos is doing that for you and setting the vector to the terrain's normal vector.

Share this post


Link to post
Share on other sites

:D thanks again. This makes me think that you are the only one who helps people over here. so maybye you know how to help with this?

and is there some way to make that it will flip all Vehicles instead of only cars?

Edited by sudslv

Share this post


Link to post
Share on other sites

Nah, I'm totally not the only one, I'm just bored and looking for issues easy enough for me to help, nothing more ;b

There are really experienced ppl in here who are clearly out of my league :D

Change

_veh = nearestobjects [player,["car"],10]; 

to

_veh = nearestobjects [player,["car","motorcycle","tank","air","ship"],10]; 

I don't know if it's make any sense to flip ships and aircrafts, but well, you wanted all vehicles :)

Share this post


Link to post
Share on other sites

i finnaly tested this and it doesnt set vector, it just bumps the vehicle 0.5m above ground.

// Locate nearby vehicle.
_veh = nearestobjects [player,["car","motorcycle","tank","air"],10];   
// Flip vehicle 0.5m above ground. 
{ 
   _newPos = getPosASL _x;                          // get the position of the current vehicle in the array 
   _newPos set [2, (_newPos select 2)+0.5];   // add 0.5m to Z-Coord 

   _x setPosASL _newPos;                             // set the new position 
} forEach _veh; 

hint "You flipped car"; 

Edited by sudslv

Share this post


Link to post
Share on other sites

Ah sry, it was setPos, not setPosASL.

// Locate nearby vehicle.
_veh = nearestobjects [player,["car","motorcycle","tank","air"],10];   
// Flip vehicle 0.5m above ground. 
{ 
   _newPos = getPos _x;                          // get the position of the current vehicle in the array 
   _newPos set [2, (_newPos select 2)+0.5];   // add 0.5m to Z-Coord 

   _x setPos _newPos;                             // set the new position 
} forEach _veh; 

Share this post


Link to post
Share on other sites
Locate nearby vehicle.

_veh = nearestobjects [player,["car","motorcycle","tank","air"],10];

// Flip vehicle 0.5m above ground.

{

_newPos = getPos _x; // get the position of the current vehicle in the array

_newPos set [2, (_newPos select 2)+0.5]; // add 0.5m to Z-Coord

_x setPos _newPos; // set the new position

} forEach _veh;

Can't get this to work. I'm calling it with a trigger from a script. It fires okay, but I just get a little bump, like driving over a speed bump...

---------- Post added at 10:26 ---------- Previous post was at 10:25 ----------

Is this script is meant to flip a vehicle on the move? Maybe I've understood it all wrong!

Share this post


Link to post
Share on other sites

This script is intended to use for vehicles which have flipped over and therefore can't drive anymore.

Executing the code-lines above will position the vehicle with it's Z-Coordinate pointing into the air, allowing the vehicle to drive again.

Share this post


Link to post
Share on other sites

Ah, I see, sorry! Totally misunderstood. I was looking for a way to flip a vehicle with a trigger while on the move...

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  

×