• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Automatic artillery

OK so I extended the IS2CannonShellHE to enable variable lauch speed and trajectory. It is then spawned in a ScriptedTrigger with wait times etc. to simulate an artillery barrage from off map. The scriptedTriggers are at the edge of the map. The projectile spawns OK and the purpose of the code below is to set the Speed, Pitch and Yaw of the shell as soon as it is created.

My questions are

1. Is PostBeginPlay() called on every object as soon as it is spawned, or is it only called once at the start of the game on each actor in existance at that time? If so then the code below wont work as PostBeginPlay() won't be called.

2. Does each IS2CannonShellHE automatically derive its rotation values from the bone in the tankgun. I was reading that Actors that are spawned inherit the rotation of the instigator of the spawn- in this case the ScriptedTrigger, and this seems to be the case with a standard IS2CannonShellHE. It travels exactly where the ScriptedTrigger is pointing. So far so good. What I am assuming is that the Rotation of the RODistantArtyShell is set to the Rotation of the ScriptedTrigger at creation, so that when PostBeginPlay() is called , the Rotation of the shell can be modified from there to get a randomised trajectory. If the values aren't set before PostBeginPlay() is called then this wont work.

What currently happens in game is that the shells fire up at about a 75 degree angle from horizontal, but there is no variation in range, speed (they all hit the roof at the same time), or trajectory( the shots are the same each time). I have about 12 duplicate ScriptedTriggers at each side of the map.



Hopefully that made sense


CODE WARNING :)


[ code ]



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//

// RODistantArtyShell -5 inch artillery

//

//

// (C) Slashbot_427 2006

//

//

// RODistantArtyShell extends IS2CannonShellHE

//

//

// This class extends the IS2 122mm cannon shell for use as a spawned
actor in a ScriptedTrigger, placed on the edge of the map. It is
"Fired" (Spawned) by the

// ScriptedTrigger to simulate distant artillery. The scripted trigger
is arranged to fire salvos of about 5 shells over a minute with a
minute pause. The things

// that need changing compared to the standard 122mmHE shell are:- the
explosion effect, Explosion sound, trajectory randomised within a
range, randomised speed

// (slower so that it falls more vertically).

//

// I am aiming to set the explosion effect to the standard arty effect

// I am aiming to set the explosdion sound to the standard arty sound

// I an aiming to set the trajectory to about +/_ 90 degrees horizontal
and +45/-15 degrees vertical of the rotation of the ScriptedTrigger

// I am aiming to set the speed to between 0.5 and 1 times the standard speed of a CannonShellHE122MM

//

// *The shells are not meant to be Uber destruction - just extra effects that may damage if struck *

//

//

// Version 0.1 12/11/06

//

//

//

//

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////









class RODistantArtyShell extends IS2CannonShellHE;





simulated function PostBeginPlay()

//

// Trying to initialise the speed and direction (Rotation) variables as soon as the projectile is spwawned.

// I think that sort of thing is done in PostBeginPlay() The projectile is spawned with the rotation values

// from the Scrited trigger. These are then modified.

//

//

{



local float SpeedFactor; // Multiplies by the speed to reduce/randomise the launch distance

local float VerticalAngle; // Angle from horixontal to verticle that the projectile launches.

local float HorizontalAngle; // Angle from side to side that the projectile launches.

local float VerticalAngleRange; // Range of angle from horixontal to
verticle that the projectile launches.

local float HorizontalAngleRange; // Range of angle from side to side that the projectile launches.



// initialise variables



VerticalAngleRange= 8192; // 45 degrees

HorizontalAngleRange = 16384; // 90 degrees











// Calculate speed of projectile



SpeedFactor =

(



FRand() * FRand() // Binomial distribution of values



);

Speed = (SpeedFactor * Speed); // not sure if this will work due to self reference?







// Calculate Trajectory





VerticalAngle =(FRand() * FRand() * VerticalAngleRange) -
(VerticalAngleRange/2); // Calcutale angle from normal (Scripted
trigger rotation)



Rotation.X = Rotation.X + VerticalAngle;









HorizontalAngle = (FRand() * FRand() * HorizontalAngleRange) -
(HorizontalAngleRange/3); // Calcutale angle from normal (Scripted
trigger rotation)





Rotation.Y = Rotation.Y + HorizontalAngle;









}

















defaultproperties



{







}

[ /code ]

This is the entire code from my extended class.
 
Last edited:
So the modified code below doesnt work, not sure where to go now.



Code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//    RODistantArtyShell         -5 inch artillery
//
//
//    (C)   Slashbot_427  2006
//
//
//    RODistantArtyShell extends CannonShellHE122MM
//
//
//    This class extends the IS2 122mm cannon shell for use as a spawned actor in a ScriptedTrigger, placed on the edge of the map.  It is "Fired" (Spawned)  by the 
//    ScriptedTrigger to simulate distant artillery.  The scripted trigger is arranged to fire salvos of about 5 shells over a minute with a minute pause. The things
//    that need changing compared to the standard 122mmHE shell are:- the explosion effect, Explosion sound, trajectory randomised within a range, randomised speed 
//    (slower so that it falls more vertically).
//    
//    I am aiming to set the explosion effect to the standard arty effect
//    I am aiming to set the explosdion sound to the standard arty sound
//    I an aiming to set the trajectory to about +/_ 90 degrees  horizontal and +45/-15 degrees vertical of the rotation of the ScriptedTrigger
//    I am aiming to set the speed to between 0.5 and 1 times the standard speed of a CannonShellHE122MM
//    
//    *The shells are not meant to be Uber destruction - just extra effects that may damage if struck *
//
//    
//    Version 0.1    12/11/06
//    
//    
//    
//    
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




class  RODistantArtyShellHE extends IS2CannonShellHE;


function PostBeginPlay()



{



//
//  Trying to initialise the speed and direction (Rotation)  variables as soon as the projectile is spwawned.  
//  I think that sort of thing is done in PostBeginPlay()  The projectile is spawned with the rotation values 
//  from the Scrited trigger. These are then modified.
//

//


    local  float VerticalAngleRange;                                                        //  Range of angle from horixontal to verticle that the projectile launches.
    local  float HorizontalAngleRange;                                                        //  Range of angle from side to side that the projectile launches.
    
    //  initialise variables
    
    VerticalAngleRange = 8192;                                                                // 45 degrees
    HorizontalAngleRange = 16384;                                                            // 90 degrees
    
    
    
    //  Calculate elevation
    Self.Veloctiy.x = RandRange(0,VerticalAngleRange)-(VerticalAngleRange/2) + Self.Velocity.x;             // centered on initial velocity +/- 4096
    
    //  Calculate Horizontal deflection
    Self.Velocity.y = RandRange(0,HorizontalAngleRange)-(HorizontalAngleRange/2) + Self.Velocity.y;         // centered on initial velocity +/- 8192
    
    //Self.Rotation = Normal(Velocity);                                                        // set rotation to direction of travel    i think
        
    
    
}
 
Upvote 0