Author Topic: Help with Projectile direction  (Read 845 times)

How do I change the direction of the Warplane bomb? Im trying to make it fire forward. I tried looking for other Funtion OnFire scripts but I cant find any good ones.

Code: [Select]
function Warplanevehicle::onTrigger(%this, %obj, %triggerNum, %val)
{
if(%triggerNum == 2 && %val && !iseventpending(%obj.rocketreload)){
%obj.client = %obj.getcontrollingclient();
%pos = %obj.getposition();
%client = %obj.client;
%pos = vectoradd(%pos,"0 0 -0.8");
%pos = vectoradd(%pos,%obj.getforwardvector());
%vel = "0 0 -22.5";
%planevz = getword(%obj.getvelocity(),2);
if(%planevz < 0){
%vel = VectorAdd(%vel,"0 0 " @ %planevz);
}
%p = new Projectile()
{
dataBlock = rocketlauncherprojectile;
initialVelocity = %vel;
initialPosition = %pos;
client = %obj.client;
sourceObject = %obj.client.player;
sourceClient = %obj.client;
};

I tried changin %vel = "0 0 -22.5"; to -90 but it dosent seem to work. Thanks in advance.

Look at the Dual Guns code.  This should get you started:

Code: [Select]
%projectile = %this.projectile;
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * 0.0005;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * 0.0005;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * 0.0005;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
     dataBlock = %projectile;
     initialVelocity = %velocity;
     initialPosition = %obj.getMuzzlePoint(%slot);
     sourceObject = %obj;
     sourceSlot = %slot;
     client = %obj.client;
 };

MissionCleanup.add(%p);

If you set it up so that it inherits the velocity from the parent (vehicle), it shouldn't be a problem.