| Blockland Forums > Modification Help |
| anyway of having two muzzle points? |
| (1/2) > >> |
| Protoss Dragoon:
is this even possible? to perhaps make a double barreled weapon ? |
| Masterlegodude:
You can probably just get away with centering the muzzlePoint between the barrels and using the multi-projectile and projectile spread script from Ephialtes' shotgun --- Code: --- %projectile = %this.projectile; %spread = 0.0015; %shellcount = 3; for(%shell=0; %shell<%shellcount; %shell++) { %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 * %spread; %y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread; %z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread; %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); } return %p; --- End code --- |
| Protoss Dragoon:
--- Quote from: Masterlegodude on January 10, 2018, 11:26:24 PM ---You can probably just get away with centering the muzzlePoint between the barrels and using the multi-projectile and projectile spread script from Ephialtes' shotgun --- End quote --- thanks |
| Swollow:
put the muzzle point in the middle when creating projectiles just do a little bit of math to create a projectile or projectiles at 2 locations --- Code: ---function gunImage::onFire(%db,%pl,%slot) { %upHack = %pl.getUpVectorHack(); %muzBase = %pl.getMuzzlePoint(%slot); %forward = %pl.getMuzzleVector(%slot); %muzPos0 = vectorAdd(%muzBase,vectorRelativeShift(%forward,%upHack,0 SPC -1 SPC 0)); %muzPos1 = vectorAdd(%muzBase,vectorRelativeShift(%forward,%upHack,0 SPC 1 SPC 0)); %proj = %db.projectile; %pvel = %pl.getVelocity(); %vel = vectorAdd(%proj.muzzleVelocity,vectorScale(%pvel,%proj.velInheritFactor)); for(%i=0;%i<=1;%i++) { %p = new projectile() { dataBlock = %proj; initialVelocity = %vel; initialPosition = %muzPos[%i]; sourceObject = %pl; sourceSlot = %slot; client = %pl.client; }; missionCleanup.add(%p); } } function vectorRelativeShift(%forward,%up,%shift) { return vectorAdd(vectorAdd(vectorScale(%forward,getWord(%shift,0)),vectorScale(vectorCross(%forward,%up),getWord(%shift,1))),vectorScale(%up,getWord(%shift,2))); } function vectorAngleRotate(%vec,%ref,%ang) { %x = getWord(%vec,0); %y = getWord(%vec,1); %z = getWord(%vec,2); %u = getWord(%ref,0); %v = getWord(%ref,1); %w = getWord(%ref,2); %cos = mCos(%ang); %sin = mSin(%ang); return %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%x*%cos+(%v*%z-%w*%y)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%y*%cos+(%w*%x-%u*%z)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%z*%cos+(%u*%y-%v*%x)*%sin; } function player::getUpVectorHack(%pl) { %muz = MatrixMulVector(%pl.getSlotTransform(0),"0 1 0"); %forward = %pl.getForwardVector(); %up = %pl.getUpVector(); return vectorAngleRotate(%muz,vectorCross(%forward,%up),$PI/2); } --- End code --- this would create two projectiles when the gun fires, one shifted 1 unit to the left and the other shifted 1 unit to the right obviously if you wanted to create some projectiles spreading you could use some spread code to create multiple projectiles at each point the bottom 3 functions are just support functions and you don't need to worry about anything in them the only thing you need to tinker with is muzPos0 and muzPos1 and the projectile creation part |
| Gytyyhgfffff:
--- Quote from: Swollow on January 11, 2018, 06:33:14 PM --- --- End quote --- that version of vectorRelativeShift forgets up when you aim upwards so don't use it. use this stuff instead --- Code: ---function vectorRelativeShift(%forwardVector, %shift) { %rightVector = VectorNormalize(VectorCross(%forwardVector, "0 0 1")); %upVector = VectorNormalize(VectorCross(%rightVector, %forwardVector)); %shiftX = getWord(%shift, 0); %shiftY = getWord(%shift, 1); %shiftZ = getWord(%shift, 2); %result = "0 0 0"; %result = VectorAdd(%result, VectorScale(%rightVector, %shiftX)); %result = VectorAdd(%result, VectorScale(%forwardVector, %shiftY)); %result = VectorAdd(%result, VectorScale(%upVector, %shiftZ)); return %result; } --- End code --- this correctly transforms the muzzle position. for %shift, x is left/right, y is forward/backwards, and z is up/down |
| Navigation |
| Message Index |
| Next page |