Announcement

Collapse
No announcement yet.

how do i script a projectile which spawns randomly in game ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    if you want to spawn at random times,

    use a timer

    Code:
    //run starttimer once from another func
    //like postbeginplay()
    //or startProjectileSpawning()
    function starttimer(){
       float randomFloat;
    
       //initialize timer for random duration
       //of 0.1 to 10 seconds
       randomFloat = randRange(0.1, 10);
       SetTimer(randomFloat, false, 'spawnProj');
    }
    
    //use code from my post, but note you cannot pass parameters
    //put all code inside the function itself.
    function spawnProj(){
      
      local Projectile SpawnedProjectile;
      local vector startLocation;
      local vector projDirection;
    
      startLocation = //game specific, you will have to decide possible range of start locations
      projDirection = vrand(); //random direction, or use more game-specific code
    
      SpawnedProjectile = Spawn(class'ProjectileClass',,, startLocation);
      
      if( SpawnedProjectile != None && !SpawnedProjectile.bDeleteMe )
      {
    	SpawnedProjectile.Init(projDirection);
      }
    
       //reset timer to a random duration
       starttimer();
    }

    Leave a comment:


  • replied
    To spawn a projectile and give it a direction (the speed of projectile comes from the actual projectile class)

    I assume you use a projectile that is a subclass of the base Projectile.uc class

    Code:
    function spawnProj(vector startLocation, vector projDirection){
      
      local Projectile SpawnedProjectile;
      
      SpawnedProjectile = Spawn(class'ProjectileClass',,, startLocation);
      
      if( SpawnedProjectile != None && !SpawnedProjectile.bDeleteMe )
      {
    	SpawnedProjectile.Init(projDirection);
      }
    }


    To give a projectile a RANDOM direction use vrand() for the projDirection



    Rama

    Leave a comment:


  • replied
    What exactly do you mean by randomly. Could you create a trigger volume to trigger the spawning?

    Leave a comment:


  • how do i script a projectile which spawns randomly in game ?

    Heys guys, Im making a SideScroller game and i was hoping to find out how would i script a projectile which spawns randomly in game?
Working...
X