Jump to content
Adrihado

(Solved with working solution) Mounting Prop to contact Drone and rotating with camera movement

Recommended Posts

Hello,

 

I have been trying to mod a drone from the contact campaign to have a extra weapon added to it. This was easy enough and is working well. I have got it to the point where the PKP will also dissapear when the drone is put into transport mode and reappear when placed down. The problem i am facing is that i cannot get the cosmetic PKP ontop to follow the gun barrel of the Contact drone correctly. Please see the vid below for the issue.

Basically it does not seem to be referencing correctly to the barrel of the gun. I am not entirely sure where to go from this point to fix the issue.
The main code for the weapon attachment is being executed as a sqf:

Wep1 setDamage 1;  
Wep1 attachTo [Drone1,[0,0.05,0.05],"arm3"];  
while {true} do  
{  
  
_dir = (drone1 weaponDirection currentWeapon drone1);  
Wep1 setVectorDirAndUp [[(_dir select 0)+0.7,(_dir select 1) +0.7,(_dir select 2) + 1],[1,-0.002,0]];  
 
sleep 0.01; 
_countAlive = {alive _x} count (crew drone1);
if (_countAlive==0) then
{
    Wep1 hideObject true;
} else 
{
    Wep1 hideObject false;
}

}; 

 

The drone is executing this code to change the weapon it is using (Variable name = Drone1):
 

this removeWeapon "DeminingDisruptor_01_F";  
this removeWeapon "Laserdesignator_mounted";  
this addWeapon "CUP_Vhmg_PKT_veh";  
this addMagazine "cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M";
this addMagazine "cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M";
this addMagazine "cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M";
this addMagazine "cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M";
this addMagazine "cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M";
this addWeapon "Laserdesignator_mounted"; 
this addMagazine "Laserbatteries";




The weapon (PKM) is executing (Variable Name = Wep1):

execVM "Weapon1.sqf"; 


 



Part of the issue is that the weapon its self spawns sideways so it requires corrections to be added to the weapon to keep it facing the correct direction.
For setVector direct and up these were  [[-0,0.002,1],[1,-0.002,0]] originally before the values that you saw in the code above were found through trial and error.

It is also attached to the arm 3 of the drone as i cannot find the refrence for the gun its self. Top red triangle.
unknown.png

The weapon its self is just executing the .SQF and the drone only has the scripting for changing the weapons and ammo in it.
PKP is from CUP along with scripted weapon being used for the drone. Will have same issues with vanallia assets though.
However it will work with any weapon prop as they all spawn in sideways.

 

If anyone has any ideas on how to correct this it would be appreciated. I can also send over the mission file is needed.

Thanks in advance.

 

Share this post


Link to post
Share on other sites

Thanks to help from a friend a method to get it to work in the X axis has been found. The rest is the same as above only the .sqf file has been changed.
 

wep1 setDamage 1; 
wep1 attachTo [drone1,[0,0.05,0.05],"arm3"]; 
 
[] spawn { 
    while {true} do 
    { 
 
    _dir = [drone1, currentWeapon drone1] call BIS_fnc_weaponDirectionRelative; 
 
 
    _newDir = [_dir, 90] call BIS_fnc_rotateVector2D; 
 
    Wep1 setVectorDirAndUp [[(_newDir select  0),(_newDir select  1),45],[0,0,0.5]]; 
    sleep 0.01; 
  
_countAlive = {alive _x} count (crew drone1); 
 
 if (_countAlive==0) then 
{ 
    Wep1 hideObject true; 
} else  
{ 
    Wep1 hideObject false; 
} 
  }; 
};




Vid of current itteration:

 

To be honest this will be functional enough for most uses But if anyone knows how to get it to move in they Y axis it would be appreciated.

Share this post


Link to post
Share on other sites

Had another friend give imput and came up with this fully functional version.
Everything else is the same as above with only the .SQF file changed:
 

Wep1 setDamage 1; 
Wep1 attachTo [Drone1,[0,0.05,0.05],"arm3"]; 
 
[] spawn { 
    while {true} do 
    { 
 
    _dir = [Drone1, currentWeapon drone1] call BIS_fnc_weaponDirectionRelative; 
 
 
    _newDir = _dir ;
    Wep1 setVectorDirAndUp [[0,-(_newDir select 2),1],[_newDir select 1,-(_newDir select 0),0]]; 
  
    sleep 0.01; 
  
   _countAlive = {alive _x} count (crew drone1); 
 
 if (_countAlive==0) then 
{ 
    Wep1 hideObject true; 
} else  
{ 
    Wep1 hideObject false; 
} 
    }; 
};



completed version video:

Feel free to use if you would like.

Edited by Dedmen
Put code into codeblock. Allbold is not allowed as per forum rules.

Share this post


Link to post
Share on other sites

General code neatness updates should have been done from the start but here we are.



 

// Contact Demining Drone Weapon platform Script V1.6.
// Made by Adrihado with help from Robodog and 417 for correct vectoring of the drone weapon.
// Use Drone1 as the variable name for the drone and use Wep1 for the weapon prop being attached. Just either put this in the drone init or execute it as a SQF with the relevant class names applied.
// Enjoy


// Removes original Drone Weapon.


 Drone1 removeWeapon "DeminingDisruptor_01_F";  
 Drone1 removeWeapon "Laserdesignator_mounted";  


// Adds Weapons And Ammo for the vehicle.


 Drone1 addWeapon "CUP_Vhmg_PKT_veh";  
{Drone1 addMagazineTurret ["cup_100Rnd_TE1_Green_Tracer_762x54_PKT_M",[0]]} foreach [1,2,3,4,5];
 Drone1 addWeapon "Laserdesignator_mounted"; 
 Drone1 addMagazine "Laserbatteries";


// Makes pkp non interactable and attaches it to the drone.


 Wep1 setDamage 1; 
 Wep1 attachTo [Drone1,[0,0.05,0.05],"arm3"]; 
 
// Loop to update the positon of the drones weapon which then is sent to the attached weapon model. Sleep to stop it from updating at max rate. 0.01 works fine for most guns.


[] spawn { 
    while {true} do 
    { 
 
    _dir = [Drone1, currentWeapon drone1] call BIS_fnc_weaponDirectionRelative; 
 
 
    _newDir = _dir ;
    Wep1 setVectorDirAndUp [[0,-(_newDir select 2),1],[_newDir select 1,-(_newDir select 0),0]]; 
  
    sleep 0.01; 
  
// Hides the weapon model if the drone is picked up and then shows it again once it is placed down.
  
 _countAlive = {alive _x} count (crew drone1); 
 
  if (_countAlive==0) then 
 { 
     Wep1 hideObject true; 
 }  else  
 { 
    Wep1 hideObject false; 
 } 
    }; 
};

 

Edited by Adrihado
Put code into codeblock (Dedmen) Minor spelling corrections. (Adrihado)
  • Thanks 1

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

×