cegepmatane / projet-specialise-2022-ManoelNohra

projet-specialise-2022-ManoelNohra created by GitHub Classroom
0 stars 0 forks source link

Pouvoir tirer un projectile #13

Open Chopv1 opened 2 years ago

Chopv1 commented 2 years ago

Le personnage peut tirer un projectile et possède des collisions qui la feront disparaitre ou rebondir selon la mécanique voulut :

Chopv1 commented 2 years ago

Lorsque le joueur appuie sur le clic gauche de la souris la fonction suivante va s'enclancher faisant apparaitre un projectile et lui donnant un force initiale :

void APerso::OnFire()
{
    if (World != NULL)
    {
        SpawnRotation = GetControlRotation();

        SpawnLocation = ((MuzzleLocation != nullptr) ? 
            MuzzleLocation->GetComponentLocation() : 
            GetActorLocation()) + SpawnRotation.RotateVector(GunOffset);
        FActorSpawnParameters ActorSpawnParams;
        ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
        World->SpawnActor<AProjectile>(Projectile, SpawnLocation, SpawnRotation, ActorSpawnParams);

        if(FireSound != NULL)
        {
            UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
        }

    }
}

Il est très simple d'enlever les rebonds ou de les activer avec la commande suivante dans le constructeur du projectile

    ProjectileMovement->bShouldBounce = true;