Announcement

Collapse
No announcement yet.

need help spawning projectile

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

    need help spawning projectile

    I'm currently working on a 2d game and my character has a gun. Im trying to spawn a bullet or projectile from the end of his gun. I've seen it done but can't figure out how to do it. Does anyone know how to do this? Thanks for the help!

    Mike

    #2
    The first person template does this. The function you want is OnFire. It should look something like:

    const FRotator SpawnRotation = GetControlRotation();
    // MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
    const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);

    UWorld* const World = GetWorld();
    if (World != NULL)
    {
    // spawn the projectile at the muzzle
    World->SpawnActor<YourProjectileClassType>(ProjectileClass, SpawnLocation, SpawnRotation);
    }

    GunOffset is the position of the muzzle - this isnt an ideal way to do this of course. but you get the idea.

    Comment


      #3
      Related tutorials https://www.youtube.com/playlist?lis...uxsdw7sPfbobs0
      [LEGENDS of EPICA]

      Comment

      Working...
      X