PDA

View Full Version : [C++ snippet] Long distance actions



squirrel5153
18th April 2006, 07:43
didnt see this on any of the tuts, so heres a snippet, Acts on Movers (doors,vents, ...) and pickups (weapons, dropped grenades)

Call with a key event
i prefere GetAsyncKeyState like so :


void Keys ()
{
if(GetAsyncKeyState(0x45)&1) // 'E' Key
{
LongDistAction();
}
}
you can call that in post render or w/e like Keys();

is in angle credits to ..., well ive seen it everywhere so creds to who made it first:wank:



BOOL inline InAngle(FVector Location, INT iAimAngle)
{
FVector X,Y,Z,D;
GetAxes(MyRotation,X,Y,Z);
D = Location - MyLocation;
D /= D.Size();
if ((iAimAngle <= (FLOAT)0.00) || (iAimAngle >= (FLOAT)360.00))
{
return TRUE;
}
else
return (Dot(D,X)) >= cos(iAimAngle * PI / 360.0);
}
the code


//Server Action Proc event

void ServerAction (AActor* A)
{
AHumanController* HC = (AHumanController*)MyController;
if(HC)
{
AHumanController_execServerAction_Parms Parms;
Parms.Other = A;
UFunction* Act = HC->FindFunction(FName(TEXT("ServerAction")),FNAME_Find);
if(Act)
HC->ProcessEvent(Act,&Parms,NULL);
}
}

void LongDistAction ()
{
for(TObjectIterator<APickup> P;P;++P)
{
APickup* Pickup = *P;
if(InAngle(Pickup->Location,MyController->FovAngle))
ServerAction(Pickup);
}
for(TObjectIterator<AMover> M;M;++M)
{
AMover* Mover = *M;
if(InAngle(Mover->Location,MyController->FovAngle))
ServerAction(Mover);
}
}

you may need this too :
creds tami (or fragger?)


void inline GetAxes (FRotator R,FVector &X,FVector &Y, FVector &Z)
{
X = R.Vector();
X.Normalize();
R.Yaw += 16384;
FRotator R2 = R;
R2.Pitch = 0.f;
Y = R2.Vector();
Y.Normalize();
Y.Z = 0.f;
R.Yaw -= 16384;
R.Pitch += 16384;
Z = R.Vector();
Z.Normalize();
}
and this too

MyController = Canvas->Viewport->Actor;
MyLocation = MyController->CalcViewLocation;
MyRotation = MyController->CalcViewRotation;

No1uKnow
18th April 2006, 08:05
void inline GetAxes (FRotator R,FVector &X,FVector &Y, FVector &Z)
{
X = R.Vector();
X.Normalize();
R.Yaw += 16384;
FRotator R2 = R;
R2.Pitch = 0.f;
Y = R2.Vector();
Y.Normalize();
Y.Z = 0.f;
R.Yaw -= 16384;
R.Pitch += 16384;
Z = R.Vector();
Z.Normalize();
}

helios I guess lol....


nice tut

itwasfunny
19th April 2006, 12:34
ya nice, since many ppl wants to code c++ now, and they play on non-pb opening doors in long distance is very useful... bcoz @ legit-mode it's not that useful heheh :P

KizZamP-
19th April 2006, 14:57
nice one there :)
helios made the inangle and getaxes was made by helios and fixed by osgb(or made by osgb and fixed by helios).

gil
19th April 2006, 17:46
Very nice.
Added to the list :)

S@t@nic@
19th April 2006, 21:18
great!
to be more accurate and do ServerAction only on 1 object u point u can maybe use something like that :



AActor* GetBestActor (AActor* BestActor, AActor* Actor, FLOAT& fBestActor)
{
FLOAT PosX = 0;
FLOAT ActorDistance = (Actor->Location - MyCameraLocation).Size();
FRotator ActorRotation = (Actor->Location - MyCameraLocation).Rotation() - MyCameraRotation;
FVector ActorRelativeToPlayer = ActorRotation.Vector() * ActorDistance;

if(ActorRelativeToPlayer.X != 0)
PosX = abs((ActorRelativeToPlayer.Y / ActorRelativeToPlayer.X));

if ( BestActor == NULL )
{
fBestActor=PosX;
return Actor;
}
if ( PosX < fBestActor)
{
fBestActor=PosX;
return Actor;
}
return BestActor;
}


void LongDistAction ()
{
APickup* pPickupThisOne = NULL;
FLOAT fBT = 0.0;
for(TObjectIterator<APickup> P;P;++P)
{
APickup* Pickup = *P;
pPickupThisOne = Cast<APickup>(GetBestActor(pPickupThisOne, Pickup, fBT));
}

if(pPickupThisOne )
ServerAction(pPickupThisOne);

}

SaTaNa
19th April 2006, 21:58
HOOAH nice very nice usefull :P SaTaNiCa the best :P

itwasfunny
20th April 2006, 22:06
ya :P find for actor distance.. never thought of that lol.. (jk) but it gives me some ideas :P