this is my current piece of code related for adding spread.. i know it might be rather dirty.
now i also have what i call a jitter area which is the Jitter function shown here
so i know i can use a function in place of a rotator/vector variable to provide a new location/rotation for spawning things my problem is that when i test it out there is no rotation at all even if i set AcurracySpread=2 instead of a more reasonable 0.25. no matter what i put it has no effect what so ever.
the jitter works fine it's just the spread/rotation function isn't working.... anyways i was wondering if im just doing something stupid? i never was very good at math or equations so i may very well have overcomplicated/f'ed up the math.
extra usefull information:
-this is for a trigger actor that spawns projectiles. not a gun.
-other then this part the rest works A-ok.
-here is the rest of the code if you wish to see
Code:
var() float Accuracyspread;
function rotator randRot()
{
local rotator NewRot;
NewRot.Yaw=self.rotation.yaw+(((Frand()*1000)-(Frand()*1000))*AccuracySpread);
NewRot.pitch=self.rotation.pitch+(((Frand()*1000)-(Frand()*1000))*AccuracySpread);
NewRot.roll=self.rotation.roll;
return NewRot;
}
//later on i use this function the the spawning part.
p=spawn(ProjectileType,,,Jitter(),RandRot());
now i also have what i call a jitter area which is the Jitter function shown here
Code:
function vector Jitter()
{
local vector NewVec;
NewVec.X=self.Location.X+RandRange(SpawnJitterArea.X*-1,SpawnJitterArea.X);
NewVec.Y=self.Location.Y+RandRange(SpawnJitterArea.Y*-1,SpawnJitterArea.Y);
NewVec.Z=self.Location.Z+RandRange(SpawnJitterArea.Z*-1,SpawnJitterArea.Z);
return NewVec;
}
so i know i can use a function in place of a rotator/vector variable to provide a new location/rotation for spawning things my problem is that when i test it out there is no rotation at all even if i set AcurracySpread=2 instead of a more reasonable 0.25. no matter what i put it has no effect what so ever.
the jitter works fine it's just the spread/rotation function isn't working.... anyways i was wondering if im just doing something stupid? i never was very good at math or equations so i may very well have overcomplicated/f'ed up the math.
extra usefull information:
-this is for a trigger actor that spawns projectiles. not a gun.
-other then this part the rest works A-ok.
-here is the rest of the code if you wish to see
Spoiler!
Code:
//FA_Shooter
//
// whne triggered it'll fire a certain projectile type
// with a certain amount of "Jitter" to simulate lots of enemies
// also with a certain spread to simulate accuracy =D
//
//
//by: falidell
class FA_Shooter extends Triggers
placeable;
struct Snytt
{
var() sound Sound;
var() float Volume;
var() float Pitch;
var() float Radius;
var() bool bAttenuate;
};
var() class<Projectile> ProjectileType;
var() int Count;
var() float DelayPerProj;
var() bool DelayisROF;
var() Snytt FireingSound;
var() bool WaitTillDone;
var() float ProjectileDamage;
var() float ProjectileSpeed;
var() float DamageRadius;
var() Vector SpawnJitterArea;
var() float AccuracySpread;
var int cCount;
var Vector NewPos;
var bool TA;
var float delay;
var float areaR;
function Trigger(Actor o, Pawn EI);
function timer();
auto state Waiting
{
function trigger(Actor o, pawn EI)
{
if(Count<=0)
{
Count=1;
}
if(!DelayisROF)
{
delay=DelayPerProj;
}
else
{
delay=1/(DelayPerProj/60);
}
if(FireingSound.Radius!=0)
{
areaR=FireingSound.Radius;
}
else
{
areaR=4092;
}
cCount=Count;
gotoState('FireEm');
}
begin:
}
function reset()
{
gotoState('Waiting');
cCount=Count;
}
function vector Jitter()// returns the random spawn location based from trigger location and JitterArea
{
local vector NewVec;
NewVec.X=self.Location.X+RandRange(SpawnJitterArea.X*-1,SpawnJitterArea.X);
NewVec.Y=self.Location.Y+RandRange(SpawnJitterArea.Y*-1,SpawnJitterArea.Y);
NewVec.Z=self.Location.Z+RandRange(SpawnJitterArea.Z*-1,SpawnJitterArea.Z);
return NewVec;
}
function rotator randRot()//Returns the Random Pitch and Yaw to simulate accuracy... very simple no trig. or PI here .. no need to make it a circle spread ^_^
{
local rotator NewRot;
NewRot.Yaw=self.rotation.yaw+(((Frand()*1000)-(Frand()*1000))*AccuracySpread);
NewRot.pitch=self.rotation.pitch+(((Frand()*1000)-(Frand()*1000))*AccuracySpread);
NewRot.roll=self.rotation.roll;
return NewRot;
}
state FireEm
{
function trigger(Actor o, pawn EI)
{
if(!WaitTillDone||!TA)
{
gotoState('Waiting');
}
}
function Fire()
{
local Projectile P;
TA=True;
playsound(FireingSound.Sound,SLOT_None,FireingSound.Volume,true,areaR,FireingSound.Pitch,FireingSound.bAttenuate);
P=Spawn(ProjectileType,,,jitter(),randRot());
if(ProjectileDamage>=1)
{
P.Damage=ProjectileDamage;
}
if(ProjectileSpeed>=1)
{
p.Speed=ProjectileSpeed;
}
if(DamageRadius>=1)
{
p.DamageRadius=DamageRadius;
}
cCount--;// remove count AFTER all those settings the rest deals with trigger stuff.
if(cCount>0)
{
SetTimer(delay,false);
}
else
{
TA=False;
gotoState('Waiting');
}
}
Function timer()
{
Fire();
}
begin:
fire();
}
defaultproperties
{
bDirectional=true// that way we can see where it's pointed ^_^
}
Last edited: