2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Weapon
As a subclass of the derived grenade weaponWeapon
In the classFire
Function Additionvirtual
The keyword becomes a virtual function so that the grenade class can inherit and rewrite itProjectileWeapon
RewriteFire
Function, create a new template variable for generating projectilesFire
Function rewriting logic //生成的投射物
UPROPERTY(EditAnywhere,BlueprintReadOnly,Category = "ProjectileWeapon")
TSubclassOf<AActor> ProjectileClass;
//--------------------------------------------------------------------------------------------------
void AProjectileWeapon::Fire()
{
AActor* MyOwner = GetOwner();
if (MyOwner)
{
FVector EyeLocation;
FRotator EyeRotation;
MyOwner->GetActorEyesViewPoint(EyeLocation, EyeRotation);
FActorSpawnParameters SpawnParams;
//设置投射物生成参数:即使生成位置有碰撞,也要强行生成投射物,不进行碰撞检测处理
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
//获取枪口位置
FVector MuzzleLocation = SkeletalComponent->GetSocketLocation(MuzzleSocketName);
//生成并发射投射物
GetWorld()->SpawnActor<AActor>(ProjectileClass, MuzzleLocation, EyeRotation, SpawnParams);
}
}
C++
The name defined inActor
The blueprint is used as a bullet, and a launcher and a sphere mesh are added. The initial and maximum speeds of the launcher are set to 2000, and the projectile rebound effect is turned on. The sphere mesh turns on physical simulation.BeginPlay
Call the logic eventBeginPlay
Get the default viewing angle range fromFAutoConsoleVariableRef ACVRDebugWeaponDrawLine(TEXT("COOP.DebugWeapons"), DebugWeaponDrawLine,TEXT