Hi
I'm trying to make a custom projectile, that stays on the ground and starts following the player when he gets close enough (In a vehicle).
Been looking at the SpiderMineTrap and BioRifle projectiles and thought it looked kind of simple.
But after having written the code I just can't get the functionality I'm after.
The projectile code: (It's a bit messy since I've been trying a lot of things to figure out what is wrong)
What happens is that I shoot the projectile fine and it lands, enters the Waiting state, and if I can close enough in the correct vehicle then it starts to follow me. But once it gets to the point where it should be triggering ProcessTouch, nothing happens, it just moves under the vehicle and stays there till its lifespan runs out.
So it looks like the ProcessTouch is never triggered, and I can't figure out why - So I was hoping someone could have a look at the code and tell me what I'm doing wrong?
EDIT: The vehicles I've been testing with are the Scorpion and the Manta (besides the special SR_Vehicle_Hover vehicle mentioned in the code).
/Mal
I'm trying to make a custom projectile, that stays on the ground and starts following the player when he gets close enough (In a vehicle).
Been looking at the SpiderMineTrap and BioRifle projectiles and thought it looked kind of simple.
But after having written the code I just can't get the functionality I'm after.
The projectile code: (It's a bit messy since I've been trying a lot of things to figure out what is wrong)
Code:
class SR_AmmoMagneticMineWeapon extends UTProjectile;
var bool TimeIsUp;
var int SecondsDeployed;
var int MaxDeployTime;
var int DetectionRange;
var int ExtendedHuntingRange;
var int AttachRange;
var float MagnetismSpeed;
var Pawn LockedTarget;
simulated function Explode(vector HitLocation, vector HitNormal)
{
Shutdown();
}
simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
{
if(IsSteamRacerVehicle(Pawn(Other))) {
// Should attach and go to a STUCK state.
Explode(HitLocation, HitNormal);
} else {
`log("Not a Steam Racer Vehicle");
}
}
simulated event Landed( vector HitNormal, actor FloorActor )
{
HitWall(HitNormal, FloorActor, None);
// Start the clock on how long the mine can stay.
SetTimer(1.0, false, 'TestForDelete');
GotoState('Waiting');
}
function TestForDelete() {
if(SecondsDeployed >= MaxDeployTime) {
TimeIsUp = true;
}
if(TimeIsUp) {
Shutdown();
}
SecondsDeployed += 1;
SetTimer(1.0, false, 'TestForDelete');
}
// Mainly just overwriting to avoid the default behavior.
simulated singular event HitWall(vector HitNormal, actor Wall, PrimitiveComponent WallComp)
{
// TODO - Only get stuck if it is static geometry
SetPhysics(PHYS_None); // Stick the mine to the first surface it hits (non-Pawn).
}
/*
* Since it is unknown if we can have a single super class for all our vehicles, this
* function checks for all our vehicle types.
**/
function bool IsSteamRacerVehicle(Pawn P)
{
if(P.IsA('SR_Vehicle_Hover'))
return true;
return false;
}
simulated state Waiting
{
simulated function BeginState(Name PreviousStateName)
{
SetPhysics(PHYS_Falling);
// Start the internal radar of the mine.
SetTimer(0.5, false, 'CheckForVehicles');
}
simulated function EndState(Name NextStateName)
{
}
/*
* Check if there are vehicles in the vecinity. ALL vehicles, including the mine owners.
* The vehicle must have a person inside it.
**/
function CheckForVehicles()
{
local Controller C;
local float TimeToNextCheck;
if (!bDeleteMe) // I'm guessing it is variable used by another class to do cleaning.
{
TimeToNextCheck = 0.5;
foreach WorldInfo.AllControllers(class'Controller', C)
{
if(IsSteamRacerVehicle(C.Pawn)) {// Is it a legal target?
if(VSize(C.Pawn.Location - Location) < DetectionRange) { // Is the target close enough?
if(FastTrace(C.Pawn.Location, Location)) { // Is the target visible?
TimeToNextCheck = MaxDeployTime;
`log("WAAARGH! BAAM");
LockedTarget = C.Pawn;
GotoState('Hunting');
}
}
}
}
SetTimer(TimeToNextCheck, false, 'CheckForVehicles');
}
}
}
simulated state Hunting
{
simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
{
Explode(HitLocation, HitNormal);
// Never being called ?
}
simulated function Hunt()
{
local vector NewLoc;
local rotator TargetDirection;
local float TargetDist;
NewLoc = LockedTarget.Location - Location;
TargetDist = VSize(NewLoc);
// The target is still within the magnetic field.
if (TargetDist < (DetectionRange + ExtendedHuntingRange))
{
Velocity = Normal(NewLoc) * MagnetismSpeed;
TargetDirection = Rotator(NewLoc);
TargetDirection.Roll = 0;
SetRotation(TargetDirection);
SetTimer(0.3, false, 'Hunt');
} else {
LockedTarget = None;
GotoState('Waiting');
}
}
simulated function BeginState(Name PreviousStateName)
{
SetPhysics(PHYS_Walking);
SetTimer(0.5, false, 'Hunt');
}
}
defaultproperties
{
// Custom variables
TimeIsUp = false;
MaxDeployTime = 40;
SecondsDeployed = 0;
DetectionRange = 800;
ExtendedHuntingRange = 200;
AttachRange = 180;
MagnetismSpeed = 180;
LockedTarget = none;
speed=1200.000000
Damage=100.000000
MomentumTransfer=75000
MyDamageType=class'UTDmgType_FlakShell' // TODO - Dont have a special DMG type yet.
LifeSpan=60 // Must be longer than the maximum deploy time.
bCollideWorld=true
TossZ=+305.0
CheckRadius=40.0
bRotationFollowsVelocity=true
// The visual of the projectile
Begin Object Class=StaticMeshComponent Name=ProjectileMesh
StaticMesh=StaticMesh'WP_BioRifle.Mesh.S_Bio_Ball'
CullDistance=12000
CollideActors=false
CastShadow=false
bAcceptsLights=false
BlockRigidBody=false
BlockActors=false
bUseAsOccluder=FALSE
End Object
Components.Add(ProjectileMesh)
// A collision volume so the mine can be "Touched". NOT WORKING
Begin Object Name=CollisionCylinder
CollisionRadius=20
CollisionHeight=10
End Object
Components.Add(CollisionCylinder);
// Affected by gravity when in the air.
Physics=PHYS_Falling
CustomGravityScaling=1.0
// Determines if the Proj is deletede instantly or stays for the show (Explode).
bWaitForEffects=false;
}
What happens is that I shoot the projectile fine and it lands, enters the Waiting state, and if I can close enough in the correct vehicle then it starts to follow me. But once it gets to the point where it should be triggering ProcessTouch, nothing happens, it just moves under the vehicle and stays there till its lifespan runs out.
So it looks like the ProcessTouch is never triggered, and I can't figure out why - So I was hoping someone could have a look at the code and tell me what I'm doing wrong?
EDIT: The vehicles I've been testing with are the Scorpion and the Manta (besides the special SR_Vehicle_Hover vehicle mentioned in the code).
/Mal
Last edited: