void AMobileOpenCVCharacter::OnFire() { // try and fire a projectile if (ProjectileClass != NULL) { 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<AMobileOpenCVProjectile>(ProjectileClass, SpawnLocation, SpawnRotation); } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if(FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if(AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
void AMurphysLawCharacter::Fire() { // check if we have a weapon equipped if (HasWeaponEquipped()) { // if the weapon has been able to fire if (GetEquippedWeapon()->Fire(this)) { // Stop the character from running SetIsRunning(false); // try and play a firing animation if specified if (FireAnimation != nullptr) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != nullptr) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } // check for bullet collisions ComputeBulletCollisions(); } // We reload the weapon if it is empty and we have bullets left in our inventory if (ShouldReload()) { Reload(); } } }
void AFP_FirstPersonCharacter::OnFire() { // Play a sound if there is one if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if(FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if(AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } // Now send a trace from the end of our gun to see if we should hit anything APlayerController* PlayerController = Cast<APlayerController>(GetController()); // Calculate the direction of fire and the start location for trace FVector CamLoc; FRotator CamRot; PlayerController->GetPlayerViewPoint(CamLoc, CamRot); const FVector ShootDir = CamRot.Vector(); FVector StartTrace = FVector::ZeroVector; if (PlayerController) { FRotator UnusedRot; PlayerController->GetPlayerViewPoint(StartTrace, UnusedRot); // Adjust trace so there is nothing blocking the ray between the camera and the pawn, and calculate distance from adjusted start StartTrace = StartTrace + ShootDir * ((GetActorLocation() - StartTrace) | ShootDir); } // Calculate endpoint of trace const FVector EndTrace = StartTrace + ShootDir * WeaponRange; // Check for impact const FHitResult Impact = WeaponTrace(StartTrace, EndTrace); // Deal with impact AActor* DamagedActor = Impact.GetActor(); UPrimitiveComponent* DamagedComponent = Impact.GetComponent(); // If we hit an actor, with a component that is simulating physics, apply an impulse if ((DamagedActor != NULL) && (DamagedActor != this) && (DamagedComponent != NULL) && DamagedComponent->IsSimulatingPhysics()) { DamagedComponent->AddImpulseAtLocation(ShootDir*WeaponDamage, Impact.Location); } }
void AShaderPluginDemoCharacter::OnFire() { //Try to set a texture to the object we hit! FHitResult HitResult; FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation(); FRotator Direction = FirstPersonCameraComponent->GetComponentRotation(); FVector EndLocation = StartLocation + Direction.Vector() * 10000; FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(this); if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, QueryParams)) { TArray<UStaticMeshComponent*> StaticMeshComponents = TArray<UStaticMeshComponent*>(); AActor* HitActor = HitResult.GetActor(); if (NULL != HitActor) { HitActor->GetComponents<UStaticMeshComponent>(StaticMeshComponents); for (int32 i = 0; i < StaticMeshComponents.Num(); i++) { UStaticMeshComponent* CurrentStaticMeshPtr = StaticMeshComponents[i]; CurrentStaticMeshPtr->SetMaterial(0, MaterialToApplyToClickedObject); UMaterialInstanceDynamic* MID = CurrentStaticMeshPtr->CreateAndSetMaterialInstanceDynamic(0); UTexture* CastedRenderTarget = Cast<UTexture>(RenderTarget); MID->SetTextureParameterValue("InputTexture", CastedRenderTarget); } } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if (FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
void ATotemCharacter::OnFire() { //only server can spawn projectile theoretically // try and fire a projectile if (ProjectileClass != NULL || FireProjectileClass != NULL) { 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) { //to add owner and instigator information FActorSpawnParameters SpawnParams; SpawnParams.Owner = Cast<ATotemPlayerController>(Controller); SpawnParams.Instigator = Instigator; //When the server function is called by serve, it also execute. ServerSpawnProjectile(SpawnLocation, SpawnRotation, SpawnParams.Owner, SpawnParams.Instigator); // spawn the projectile at the muzzle single player version //World->SpawnActor<ATotemProjectile>(ProjectileClass, SpawnLocation, SpawnRotation, SpawnParams); } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if (FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
void AGWWeaponRanged::OnRep_ReloadBeign() { OnReloadBegin(); if (ReloadAnimation) { IIGISkeletalMesh* skelMeshInt = Cast<IIGISkeletalMesh>(Instigator); if (!skelMeshInt) return; UAnimInstance* AnimInst = skelMeshInt->GetMasterSkeletalMesh()->GetAnimInstance(); if (!AnimInst) return; float montageLenght = ReloadAnimation->CalculateSequenceLength(); float multiplier = montageLenght / ReloadTime; AnimInst->Montage_Play(ReloadAnimation, multiplier); } }
void AUDKPresentationCharacter::OnFire() { if (CharacterMovement->IsMovingOnGround()) { ammo = maxAmmo; } if (ammo <= 0) return; // try and fire a projectile if (ProjectileClass != NULL) { 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); ammo--; CharacterMovement->Velocity = GetControlRotation().Vector()*(-1000) + 0.5f * CharacterMovement->Velocity; UWorld* const World = GetWorld(); if (World != NULL) { // spawn the projectile at the muzzle World->SpawnActor<AUDKPresentationProjectile>(ProjectileClass, SpawnLocation, SpawnRotation); } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if(FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if(AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
void AGun::OnEquip() { Super::OnEquip(); if (WeaponEquipAnimation) { Mesh->GetAnimInstance()->Montage_Play(WeaponEquipAnimation, 1.f); } if (PlayerEquipAnimation) { UAnimInstance* AnimInstance = Cast<AFPSCodeCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0))->GetMesh1P()->GetAnimInstance(); if (AnimInstance) { AnimInstance->Montage_Play(PlayerEquipAnimation, 1.f); } } }
void AGun::Reload() { if (!IsReloading) { if (CurrentAmmo < MagSize && TotalAmmo > 0) { IsReloading = true; //Playing Reload animation on weapon if (WeaponReloadAnimation) { Mesh->GetAnimInstance()->Montage_Play(WeaponReloadAnimation, 1.f); } //Playing Reload animation montage on player if (PlayerReloadAnimation) { UAnimInstance* AnimInstance = Cast<AFPSCodeCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0))->GetMesh1P()->GetAnimInstance(); if (AnimInstance) { bCanAttack = false; float AnimTime = AnimInstance->Montage_Play(PlayerReloadAnimation, 1.f); FTimerHandle AnimHandle; GetWorld()->GetTimerManager().SetTimer(AnimHandle, this, &AGun::SetAmmoValues, AnimTime); //Set timer to apply reloaded ammo values when animation is done } else { SetAmmoValues(); } } else { SetAmmoValues(); } } } }
float ACharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName) { UAnimInstance * AnimInstance = (Mesh)? Mesh->GetAnimInstance() : NULL; if( AnimMontage && AnimInstance ) { float const Duration = AnimInstance->Montage_Play(AnimMontage, InPlayRate); if (Duration > 0.f) { // Start at a given Section. if( StartSectionName != NAME_None ) { AnimInstance->Montage_JumpToSection(StartSectionName, AnimMontage); } return Duration; } } return 0.f; }
void ABETCharacter::OnFire() { if (Weapon){ Weapon->Fire(); } // try and play the sound if specified if (Weapon->FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, Weapon->FireSound, GetActorLocation()); } // try and play a firing animation if specified if (Weapon->FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(Weapon->FireAnimation, 1.f); } } }
void AWizardsCharacter::OnFire() { if (!mySpellBook.IsValidIndex(0)) { UE_LOG(LogTemp, Warning, TEXT("Spell Gathering Needed!")); newCharactersSpells(); } if (Mana > mySpellBook[currSpell].spellCost) { Mana -= mySpellBook[currSpell].spellCost; // try and fire a projectile if (mySpellBook[currSpell].spellType == 0) { const FRotator SpawnRotation = GetControlRotation(); const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset); UWorld* const World = GetWorld(); if (World) { // spawn the projectile at the muzzle /*UParticleSystem* projParticle = particleList[mySpellBook[currSpell].spellEffect + mySpellBook[currSpell].spellType * 5]; UParticleSystem* blastParticle = particleList[mySpellBook[currSpell].spellEffect + 5]; AWizardsProjectile* wizardsSpell = World->SpawnActor<AWizardsProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);// , myparams); wizardsSpell->SpellCreation(&mySpellBook[currSpell], projParticle, blastParticle, this);*/ if (Role < ROLE_Authority) { ServerFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation);//mySpellBook[currSpell]); } else { ClientFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation); } } } else if (mySpellBook[currSpell].spellType == 1) { const FRotator SpawnRotation = FRotator(0.0);//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 = FVector(0.0);//GetActorLocation() + SpawnRotation.RotateVector(GunOffset); UWorld* const World = GetWorld(); if (World) { // spawn the projectile at the muzzle /*UParticleSystem* blastParticle = particleList[mySpellBook[currSpell].spellEffect + mySpellBook[currSpell].spellType * 5]; AWizardsBlast* wizardsSpell = World->SpawnActor<AWizardsBlast>(BlastClass, SpawnLocation, SpawnRotation);// , myparams); wizardsSpell->SpellCreation(blastParticle, mySpellBook[currSpell].spellSize, mySpellBook[currSpell].spellDamage, this); wizardsSpell->AttachRootComponentTo(GetCapsuleComponent());//Probably useful for Blasts, Rays, and Conical attacks*/ if (Role < ROLE_Authority) { ServerFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation); } else { ClientFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation); } } } else if (mySpellBook[currSpell].spellType == 2) { const FRotator SpawnRotation = FRotator(0.0);//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 = FVector(0.0);//GetActorLocation() + SpawnRotation.RotateVector(GunOffset); UWorld* const World = GetWorld(); if (World) { // spawn the projectile at the muzzle /*UParticleSystem* coneParticle = particleList[mySpellBook[currSpell].spellEffect + mySpellBook[currSpell].spellType * 5]; AWizardsCone* wizardsCone = World->SpawnActor<AWizardsCone>(ConeClass, SpawnLocation, SpawnRotation);// , myparams); wizardsCone->SpellCreation(coneParticle, mySpellBook[currSpell].spellSize, mySpellBook[currSpell].spellDamage, this); wizardsCone->AttachRootComponentTo(GetCapsuleComponent());//Probably useful for Blasts, Rays, and Conical attacks activeAttack = Cast<AActor>(wizardsCone);*/ if (Role < ROLE_Authority) { ServerFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation); } else { ClientFireProjectile(mySpellBook[currSpell], SpawnRotation, SpawnLocation); } } } // God this sound is so annoying /*if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); }*/ // try and play a firing animation if specified if (FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } } }