// Called every frame void ATopDown_HitmanCleanCharacter::Tick( float DeltaTime ){ Super::Tick( DeltaTime ); // Handle growing and shrinking based on our "Grow" action { float CurrentScale = GetCapsuleComponent()->GetComponentScale().X; if (bGrowing){ // Grow to double size over the course of one second CurrentScale += DeltaTime; } else{ // Shrink half as fast as we grow CurrentScale -= (DeltaTime * 0.5f); } // Make sure we never drop below our starting size, or increase past double size. CurrentScale = FMath::Clamp(CurrentScale, 1.0f, 2.0f); GetCapsuleComponent()->SetWorldScale3D(FVector(CurrentScale)); } // Handle movement based on our "MoveX" and "MoveY" axes { if (!CurrentVelocity.IsZero()){ FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime); SetActorLocation(NewLocation); } } }
// Sets default values APlayerCharacter::APlayerCharacter() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; GetCapsuleComponent()->InitCapsuleSize(42.f, 90.f); BaseTurnRate = 60.f; BaseLookUpRate = 60.f; FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); FirstPersonCameraComponent->bUsePawnControlRotation = true; Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; //BOX PICKUP CODE// Hand = CreateDefaultSubobject<USceneComponent>(TEXT("Hand")); Hand->AttachTo(FirstPersonCameraComponent); Hand->RelativeLocation = FVector(100, 0, 0); //BOX PICKUP CODE// OnActorBeginOverlap.AddDynamic(this, &APlayerCharacter::OnActorOverlap); OnActorEndOverlap.AddDynamic(this, &APlayerCharacter::OnActorOverlapEnd); PhysicsHandler = CreateDefaultSubobject<UPhysicsHandleComponent>(TEXT("PhysicsHandler")); }
void ADA2UE4Creature::BeginPlay() { Super::BeginPlay(); //temp CursorToWorld->SetVisibility(false, true); CursorToWorld = nullptr; if (PawnSensingComp) { PawnSensingComp->OnSeePawn.AddDynamic(this, &ADA2UE4Creature::OnSeePlayer); PawnSensingComp->OnHearNoise.AddDynamic(this, &ADA2UE4Creature::OnHearNoise); } GetCapsuleComponent()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); //add over events GetCapsuleComponent()->OnClicked.AddDynamic(this, &ADA2UE4Creature::OnClick); GetCapsuleComponent()->OnBeginCursorOver.AddDynamic(this, &ADA2UE4Creature::BeginCursorOver); GetCapsuleComponent()->OnEndCursorOver.AddDynamic(this, &ADA2UE4Creature::EndCursorOver); PrimaryActorTick.AddPrerequisite(MeshHEDComponent, MeshHEDComponent->PrimaryComponentTick); //Animation = Cast<UDA2UE4AnimInstance>(MeshHEDComponent->GetAnimInstance()); //Animation->Montage_Play(Montage); SetupCustomMontages(); }
AValorMinionSpawner::AValorMinionSpawner(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { GetCapsuleComponent()->InitCapsuleSize(40.0f, 92.0f); #if WITH_EDITORONLY_DATA ArrowComponent = CreateEditorOnlyDefaultSubobject<UArrowComponent>(TEXT("Arrow")); if (!IsRunningCommandlet()) { // Structure to hold one-time initialization struct FConstructorStatics { ConstructorHelpers::FObjectFinderOptional<UTexture2D> PlayerStartTextureObject; FName ID_PlayerStart; FText NAME_PlayerStart; FName ID_Navigation; FText NAME_Navigation; FConstructorStatics() : PlayerStartTextureObject(TEXT("/Engine/EditorResources/S_Player")) , ID_PlayerStart(TEXT("PlayerStart")) , NAME_PlayerStart(NSLOCTEXT("SpriteCategory", "PlayerStart", "Player Start")) , ID_Navigation(TEXT("Navigation")) , NAME_Navigation(NSLOCTEXT("SpriteCategory", "Navigation", "Navigation")) { } }; static FConstructorStatics ConstructorStatics; if (GetGoodSprite()) { GetGoodSprite()->Sprite = ConstructorStatics.PlayerStartTextureObject.Get(); GetGoodSprite()->RelativeScale3D = FVector(0.5f, 0.5f, 0.5f); GetGoodSprite()->SpriteInfo.Category = ConstructorStatics.ID_PlayerStart; GetGoodSprite()->SpriteInfo.DisplayName = ConstructorStatics.NAME_PlayerStart; } if (GetBadSprite()) { GetBadSprite()->SetVisibility(false); } if (ArrowComponent) { ArrowComponent->ArrowColor = FColor(150, 200, 255); ArrowComponent->ArrowSize = 1.0f; ArrowComponent->bTreatAsASprite = true; ArrowComponent->SpriteInfo.Category = ConstructorStatics.ID_Navigation; ArrowComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_Navigation; ArrowComponent->SetupAttachment(GetCapsuleComponent()); ArrowComponent->bIsScreenSizeScaled = true; } } #endif // WITH_EDITORONLY_DATA if (GWorld && GWorld->HasBegunPlay()) { ensure(SpawnTeam != EValorTeam::Invalid); } }
// Sets default values ASZombieCharacter::ASZombieCharacter(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { /* Note: We assign the Controller class in the Blueprint extension of this class Because the zombie AIController is a blueprint in content and it's better to avoid content references in code. */ /*AIControllerClass = ASZombieAIController::StaticClass();*/ /* Our sensing component to detect players by visibility and noise checks. */ PawnSensingComp = CreateDefaultSubobject<UPawnSensingComponent>(TEXT("PawnSensingComp")); PawnSensingComp->SetPeripheralVisionAngle(60.0f); PawnSensingComp->SightRadius = 2000; PawnSensingComp->HearingThreshold = 600; PawnSensingComp->LOSHearingThreshold = 1200; /* Ignore this channel or it will absorb the trace impacts instead of the skeletal mesh */ GetCapsuleComponent()->SetCollisionResponseToChannel(COLLISION_WEAPON, ECR_Ignore); GetCapsuleComponent()->SetCapsuleHalfHeight(96.0f, false); GetCapsuleComponent()->SetCapsuleRadius(42.0f); /* These values are matched up to the CapsuleComponent above and are used to find navigation paths */ GetMovementComponent()->NavAgentProps.AgentRadius = 42; GetMovementComponent()->NavAgentProps.AgentHeight = 192; Health = 100; PunchDamage = 10.0f; /* By default we will not let the AI patrol, we can override this value per-instance. */ BotType = EBotBehaviorType::Passive; SenseTimeOut = 2.5f; /* Note: Visual Setup is done in the AI/ZombieCharacter Blueprint file */ }
ALD35Character::ALD35Character() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; static ConstructorHelpers::FObjectFinder<USoundBase> s1(TEXT("/Game/Sound/SeeWereTiger/SeeSoundCue")); SeeWereTigerSound = s1.Object; static ConstructorHelpers::FObjectFinder<USoundBase> s2(TEXT("/Game/Sound/SeeEnemy/SeeSoundCue")); LetsMoveSound = s2.Object; static ConstructorHelpers::FObjectFinder<USoundBase> s3(TEXT("/Game/Sound/Death/DeathSoundCue")); DeathSound = s3.Object; static ConstructorHelpers::FObjectFinder<USoundBase> s4(TEXT("/Game/Sound/Hit/SoundCue")); HitSound = s4.Object; static ConstructorHelpers::FObjectFinder<USoundBase> s5(TEXT("/Game/Sound/CrossbowShot/SoundCue")); ShootCrossbowSound = s5.Object; static ConstructorHelpers::FObjectFinder<USoundBase> s6(TEXT("/Game/Sound/Transform/SoundCue")); TransformSound = s6.Object; }
void ACarcinusCharacter::SetHealth(int damage) { Super::SetHealth(damage); mEnemyHealth = mEnemyHealth - damage; if (mEnemyHealth <= 0) { GetMesh()->SetCollisionProfileName("Ragdoll"); GetMesh()->SetSimulatePhysics(true); GetWorld()->GetTimerManager().SetTimer(mDeathTimeHandler, this, &ACarcinusCharacter::DisablePhysics, 10.0f, false); ACharacter* PlayerRef = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); FString DeathEvent = "Event_CrabDeath"; AAudioManager::GetInstance()->PlayWwiseEvent(DeathEvent, PlayerRef); AAudioManager::GetInstance()->SetFearValue(1.0f); ParticleComponent->Activate(true); if (GetCapsuleComponent() != NULL) { GetCapsuleComponent()->DestroyComponent(); } if (HeadCollider != NULL) { HeadCollider->DestroyComponent(); } } mEnemyHealth = FMath::Clamp(mEnemyHealth, 0, mEnemyMaxHealth); }
AAlphaCog01Character::AAlphaCog01Character() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; // Default offset from the character location for projectiles to spawn GunOffset = FVector(100.0f, 30.0f, 10.0f); // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn) Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); // only the owning player will see this mesh Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->RelativeLocation = FVector(0.f, 0.f, -150.f); Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; // Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the // derived blueprint asset named MyCharacter (to avoid direct content references in C++) }
ARTJamCharacter::ARTJamCharacter() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ARTJamCharacter::OnHit); // Don't rotate when the controller rotates. bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Face in the direction we are moving.. GetCharacterMovement()->RotationRate = FRotator(0.0f, 720.0f, 0.0f); // ...at this rotation rate GetCharacterMovement()->GravityScale = 2.f; GetCharacterMovement()->AirControl = 0.80f; GetCharacterMovement()->JumpZVelocity = 1000.f; GetCharacterMovement()->GroundFriction = 3.f; GetCharacterMovement()->MaxWalkSpeed = 600.f; GetCharacterMovement()->MaxFlySpeed = 600.f; // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++) bIsDead = false; NormalImpulse = 800.f; MaxImpulse = 1000.f; ForceLength.Z = NormalImpulse; }
ABETCharacter::ABETCharacter() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn) Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; // Create a gun mesh component FP_Gun = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FP_Gun")); FP_Gun->SetOnlyOwnerSee(true); // only the owning player will see this mesh FP_Gun->bCastDynamicShadow = false; FP_Gun->CastShadow = false; FP_Gun->AttachTo(Mesh1P, TEXT("GripPoint"), EAttachLocation::SnapToTargetIncludingScale, true); // Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the // derived blueprint asset named MyCharacter (to avoid direct content references in C++) }
AFPSHorrorCharacter::AFPSHorrorCharacter() { //test Health = MaxHealth; DecayingRate = 1.5f; // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; // Scene Color Settings FirstPersonCameraComponent->PostProcessSettings.bOverride_SceneColorTint = true; FirstPersonCameraComponent->PostProcessSettings.bOverride_VignetteIntensity = true; FirstPersonCameraComponent->PostProcessSettings.bOverride_GrainIntensity = true; FirstPersonCameraComponent->PostProcessSettings.bOverride_ColorContrast = true; FirstPersonCameraComponent->PostProcessSettings.bOverride_ColorGamma = true; FirstPersonCameraComponent->PostProcessSettings.bOverride_ColorGain = true; FirstPersonCameraComponent->PostProcessSettings.SceneColorTint = FLinearColor(.5f, .5f, .5f, 1.0f); FirstPersonCameraComponent->PostProcessSettings.VignetteIntensity = 0.0f; FirstPersonCameraComponent->PostProcessSettings.GrainIntensity = .15f; // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn) Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; // Create a Sowrd mesh component FP_Sword = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FP_Sword")); FP_Sword->SetOnlyOwnerSee(true); // only the owning player will see this mesh FP_Sword->bCastDynamicShadow = false; FP_Sword->CastShadow = false; FP_Sword->AttachTo(Mesh1P, TEXT("Sword"), EAttachLocation::SnapToTargetIncludingScale, true); // Create a Hammer mesh component FP_Hammer = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FP_Hammer")); FP_Hammer->SetOnlyOwnerSee(true); // only the owning player will see this mesh FP_Hammer->bCastDynamicShadow = false; FP_Hammer->CastShadow = false; FP_Hammer->AttachTo(Mesh1P, TEXT("Hammer"), EAttachLocation::SnapToTargetIncludingScale, true); // Default offset from the character location for projectiles to spawn GunOffset = FVector(100.0f, 30.0f, 10.0f); // Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the // derived blueprint asset named MyCharacter (to avoid direct content references in C++) }
// Sets default values AMainCharacter::AMainCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; bCanBeDamaged = true; bFireIsReady = true; CurrentWeapon = NULL; Inventory.SetNum(3, false); Inventory[0] = NULL; Inventory[1] = NULL; Inventory[2] = NULL; WeaponAmmoStorage.SetNum(3, false); WeaponAmmoStorage[0].CurrentSpareAmmo = -1; WeaponAmmoStorage[1].CurrentSpareAmmo = -1; WeaponAmmoStorage[2].CurrentSpareAmmo = -1; WeaponAmmoStorage[0].CurrentMagazineAmmo = -1; WeaponAmmoStorage[1].CurrentMagazineAmmo = -1; WeaponAmmoStorage[2].CurrentMagazineAmmo = -1; //WeaponSpawn = NULL; GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; GetCharacterMovement()->bCanWalkOffLedgesWhenCrouching = true; GetCharacterMovement()->MaxAcceleration = 1400.0f; GetCharacterMovement()->BrakingDecelerationWalking = 0.0f; RootComponent = GetCapsuleComponent(); FirstPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, BaseEyeHeight); FirstPersonCameraComponent->bUsePawnControlRotation = true; GetMesh()->SetOwnerNoSee(true); FirstPersonMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FirstPersonMesh")); FirstPersonMesh->SetOnlyOwnerSee(true); // only the owning player will see this mesh FirstPersonMesh->AttachParent = FirstPersonCameraComponent; FirstPersonMesh->bCastDynamicShadow = false; FirstPersonMesh->CastShadow = false; Flashlight = ObjectInitializer.CreateDefaultSubobject<USpotLightComponent>(this, TEXT("Flashlight")); Flashlight->AttachParent = FirstPersonCameraComponent; GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AMainCharacter::OnCollision); /* static ConstructorHelpers::FObjectFinder<UBlueprint> WeaponBlueprint(TEXT("Blueprint'/Game/FPS/Blueprints/Weapons/BP_Weapon_M4A1.BP_Weapon_M4A1'")); if (WeaponBlueprint.Succeeded()) { WeaponSpawn = (UClass*)WeaponBlueprint.Object->GeneratedClass; } */ }
// Sets default values ASoldierPawn::ASoldierPawn() { struct FConstructorStatics { ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> RunAnimationAsset; ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> IdleAnimationAsset; FConstructorStatics() : RunAnimationAsset(TEXT("/Game/2dSideScroller/Animation/Soldier/Run.Run")), IdleAnimationAsset(TEXT("/Game/2dSideScroller/Animation/Soldier/Idle.Idle")) { } }; static FConstructorStatics ConstructorStatics; RunAnimation = ConstructorStatics.RunAnimationAsset.Get(); IdleAnimation = ConstructorStatics.IdleAnimationAsset.Get(); GetSprite()->SetFlipbook(IdleAnimation); GetSprite()->SetRelativeScale3D(FVector(4.5, 1, 4.5)); // Use only Yaw from the controller and ignore the rest of the rotation. bUseControllerRotationPitch = false; bUseControllerRotationYaw = true; bUseControllerRotationRoll = false; // Set the size of our collision capsule. GetCapsuleComponent()->SetCapsuleHalfHeight(90); GetCapsuleComponent()->SetCapsuleRadius(43); GetCapsuleComponent()->SetRelativeLocation(FVector(-25, 0, 0)); // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. // PrimaryActorTick.bCanEverTick = true; RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component")); // Configure character movement GetCharacterMovement()->GravityScale = 2.0f; GetCharacterMovement()->AirControl = 0.80f; GetCharacterMovement()->JumpZVelocity = 1000.f; GetCharacterMovement()->GroundFriction = 3.0f; GetCharacterMovement()->MaxWalkSpeed = 600.0f; GetCharacterMovement()->MaxFlySpeed = 600.0f; // Lock character motion onto the XZ plane, so the character can't move in or out of the screen GetCharacterMovement()->bConstrainToPlane = true; GetCharacterMovement()->SetPlaneConstraintNormal(FVector(0, -1, 0)); GetCharacterMovement()->bUseFlatBaseForFloorChecks = true; }
void ARTJamCharacter::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (IsInvincible()) { GetCapsuleComponent()->SetCollisionProfileName(TEXT("OverlapAllDynamic")); } else { GetCapsuleComponent()->SetCollisionProfileName(TEXT("Pawn")); } }
ARealmEnablerShield::ARealmEnablerShield(const FObjectInitializer& objectInitializer) : Super(objectInitializer) { GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); GetCapsuleComponent()->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block); shieldCollision = CreateDefaultSubobject<USphereComponent>(TEXT("shieldCollision")); shieldCollision->InitSphereRadius(1150.f); shieldCollision->AttachParent = RootComponent; shieldCollision->SetCollisionResponseToAllChannels(ECR_Ignore); shieldCollision->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap); shieldCollision->OnComponentBeginOverlap.AddDynamic(this, &ARealmEnablerShield::OnShieldBeginOverlap); shieldCollision->OnComponentEndOverlap.AddDynamic(this, &ARealmEnablerShield::OnShieldEndOverlap); }
AInventoryPrototypeCharacter::AInventoryPrototypeCharacter() { //PrimaryActorTick.bCanEverTick = true; // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn) Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; // Create a gun mesh component FP_Gun = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FP_Gun")); FP_Gun->SetOnlyOwnerSee(true); // only the owning player will see this mesh FP_Gun->bCastDynamicShadow = false; FP_Gun->CastShadow = false; FP_Gun->AttachTo(Mesh1P, TEXT("GripPoint"), EAttachLocation::SnapToTargetIncludingScale, true); // Default offset from the character location for projectiles to spawn GunOffset = FVector(100.0f, 30.0f, 10.0f); // Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the // derived blueprint asset named MyCharacter (to avoid direct content references in C++) //stamina and movement this->stamina = 500; this->maxStamina = 1000; this->staminaRate = 1; this->isRunning = true; //inventory and items this->inventory = new Inventory(150); this->testItem = new Item(0, "ITEM", 5); this->testItem1 = new Item(1, "myItem", 10); }
AFPSGCharacter::AFPSGCharacter() : Super() { bReplicates = true; // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; GetCapsuleComponent()->bGenerateOverlapEvents = true; //Initialize the first person camera component firstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FPSGFirstPersonCamera")); firstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FVector characterViewLocation; FRotator characterViewRotation; GetActorEyesViewPoint(characterViewLocation, characterViewRotation); //Position the camera and use the view rotation of the pawn that we get from input firstPersonCameraComponent->RelativeLocation = characterViewLocation; firstPersonCameraComponent->RelativeRotation = characterViewRotation; firstPersonCameraComponent->bUsePawnControlRotation = true; //Initialize the first person mesh component firstPersonMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FPSGFirstPersonMesh")); firstPersonMesh->SetOnlyOwnerSee(true); firstPersonMesh->AttachParent = firstPersonCameraComponent; firstPersonMesh->bCastDynamicShadow = false; firstPersonMesh->CastShadow = false; //The regular body mesh should not be visible to the player GetMesh()->SetOwnerNoSee(true); movementDirection = EMoveDirection::NONE; maxHealth = 100.0f; currentHealth = 100.0f; currentWeapon = NULL; isFiring = false; isFalling = false; amountOfGrenades = 0; maxGrenades = 0; deathAnimation = NULL; inventoryWeaponSocket = ""; boneHead = ""; //Reserve memory for at least 10 elements (weapons) weaponInventory.Reserve(10); dieCallback = false; }
void ADA2UE4Creature::InitSkeletalMeshComponent(TWeakObjectPtr<class USkeletalMeshComponent> SMeshPointer, bool AttachToParent) { SMeshPointer->AlwaysLoadOnClient = true; SMeshPointer->AlwaysLoadOnServer = true; SMeshPointer->bOwnerNoSee = false; SMeshPointer->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::AlwaysTickPose; SMeshPointer->bCastDynamicShadow = true; SMeshPointer->bAffectDynamicIndirectLighting = true; SMeshPointer->PrimaryComponentTick.TickGroup = TG_PrePhysics; // force tick after movement component updates if (GetCharacterMovement()) { SMeshPointer->PrimaryComponentTick.AddPrerequisite(this, GetCharacterMovement()->PrimaryComponentTick); } //SMeshPointer->AttachParent = GetCapsuleComponent(); SMeshPointer->SetupAttachment(GetCapsuleComponent()); static FName CollisionProfileName(TEXT("CharacterMesh")); SMeshPointer->SetCollisionObjectType(ECC_Pawn); SMeshPointer->SetCollisionProfileName(CollisionProfileName); SMeshPointer->bGenerateOverlapEvents = false; // Mesh acts as the head, as well as the parent for both animation and attachment. if (AttachToParent) { //SMeshPointer->AttachParent = MeshHEDComponent; SMeshPointer->SetupAttachment(MeshHEDComponent); SMeshPointer->SetMasterPoseComponent(MeshHEDComponent); SMeshPointer->bUseBoundsFromMasterPoseComponent = true; } }
// Sets default values ABaseCharacter::ABaseCharacter() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; GetCapsuleComponent()->InitCapsuleSize(42.0f, 96.0f); //Create and set SpringArm component as our RootComponent CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 0.0f; CameraBoom->bUsePawnControlRotation = true; //Create a Camera Component and attach it to our SpringArm Component "CameraSpringArm" Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); Camera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); Camera->bUsePawnControlRotation = false; //Create a skeletalMesh for holding weapon and attach it to the character mesh WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh")); WeaponMesh->SetupAttachment(GetMesh()); FirstPersonViewMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FirstPersonViewMesh")); FirstPersonViewMesh->SetupAttachment(Camera); //Initialize default values ADSBlendInterpSpeed = 10.0f; CameraFOV = 120.0f; ADSCameraFOV = 90.0f; SprintSpeed = 600.0f; bAlwaysADS = false; bIsInFirstPersonView = true; }
// Sets default values AGhost::AGhost() : ActiveModeIndex(0) { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = false; auto Capsule = GetCapsuleComponent(); Capsule->SetCollisionObjectType(ECC_GHOST); Capsule->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block); Capsule->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); Capsule->SetCollisionResponseToChannel(ECC_PICKUP, ECollisionResponse::ECR_Ignore); PathFollowingComponent = CreateDefaultSubobject<UPacmanPathFollowingComponent>("PathFollowingComponent"); int32 NumModes = FMath::RandRange(2, 10); Modes.SetNum(NumModes); for (int32 i = 0; i < NumModes; ++i) { Modes[i].Duration = FMath::FRandRange(5.f, 20.f); Modes[i].GhostState = static_cast<EGhostState>(i % 2); } // Last state must be chased Modes.Last().GhostState = EGhostState::Chase; Modes.Last().Duration = 0.f; }
ACapTheBrainCharacter::ACapTheBrainCharacter(const class FObjectInitializer& PCIP) : Super(PCIP) { buff = 100; buffTimer = 0; buffDelay = 2; score = 0; firstUpdate = true; // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Don't rotate when the controller rotates. Let that just affect the camera. bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate GetCharacterMovement()->JumpZVelocity = 200.f; GetCharacterMovement()->AirControl = 0.2f; // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++) }
AFrisbeeNulCharacter::AFrisbeeNulCharacter() { // Set size for player capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // Don't rotate character to camera direction bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f); GetCharacterMovement()->bConstrainToPlane = true; GetCharacterMovement()->bSnapToPlaneAtStart = true; GetCharacterMovement()->MaxWalkSpeed = 1000; // Create a camera boom... CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->AttachTo(RootComponent); CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does CameraBoom->TargetArmLength = 800.f; CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f); CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level // Create a camera... TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera")); TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName); TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm }
AMutagenPlayer::AMutagenPlayer(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Don't rotate when the controller rotates. Let that just affect the camera. bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate GetCharacterMovement()->JumpZVelocity = 600.f; GetCharacterMovement()->AirControl = 0.2f; // Create a camera boom (pulls in towards the player if there is a collision) cameraBoom = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom")); cameraBoom->AttachTo(RootComponent); cameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character cameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller // Create a follow camera followCamera = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera")); followCamera->AttachTo(cameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation followCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm }
float ALD35Character::TakeDamage(float DamageAmount, FDamageEvent const & DamageEvent, AController * EventInstigator, AActor * DamageCauser) { UGameplayStatics::PlaySoundAtLocation(this, HitSound, this->GetActorLocation()); float dmg = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser); Health -= dmg; if (Health <= 0) { GetMesh()->SetSimulatePhysics(true); GetMesh()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetMovementComponent()->SetActive(false); UGameplayStatics::PlaySoundAtLocation(this, DeathSound, this->GetActorLocation()); if (EventInstigator) { if (auto a = Cast<ALD35Character>(EventInstigator->GetPawn())) { if (a->Faction == Faction) { UE_LOG(LogTemp, Display, TEXT("Teamkilling detected!")); a->Faction = FMath::Rand(); } } } } return dmg; }
ATut2Character::ATut2Character(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Don't rotate when the controller rotates. Let that just affect the camera. bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input... GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate GetCharacterMovement()->JumpZVelocity = 600.f; GetCharacterMovement()->AirControl = 0.2f; // Create a camera boom (pulls in towards the player if there is a collision) CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->AttachTo(RootComponent); CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller // Create a follow camera FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera")); FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++) }
void ABaseCharacter::OnDeath(float KillingDamage, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { bReplicateMovement = false; bTearOff = true; PlayHit(true, KillingDamage, DamageEvent, PawnInstigator, DamageCauser); DetachFromControllerPendingDestroy(); /* Disable all collision on capsule */ UCapsuleComponent* CapsuleComp = GetCapsuleComponent(); CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore); if(bRagdolledAfterDeath) { SetRagdollPhysics(); ApplyPhysicsToTheRagdolledBody(DamageEvent); } else { SetLifeSpan(TimeAfterDeathBeforeDestroy); } }
ASECharacter::ASECharacter() : Super() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(5.421325f, 44.f); // Set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; auto movement = CastChecked<UCharacterMovementComponent>(GetMovementComponent()); movement->MaxWalkSpeed = 100.f; // Create a CameraComponent CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); CameraComponent->AttachToComponent(GetCapsuleComponent(), FAttachmentTransformRules::KeepWorldTransform); CameraComponent->RelativeLocation = FVector(0.f, 0.f, GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight()); // Position the camera CameraComponent->bUsePawnControlRotation = true; }
ARadeCharacter::ARadeCharacter(const class FObjectInitializer& PCIP) : Super(PCIP) { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // Create a CameraComponent FirstPersonCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera // Create a camera boom (pulls in towards the player if there is a collision) ThirdPersonCameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom")); ThirdPersonCameraBoom->AttachTo(RootComponent); ThirdPersonCameraBoom->TargetArmLength = 150; ThirdPersonCameraBoom->RelativeLocation = FVector(0,50,100); ThirdPersonCameraBoom->bUsePawnControlRotation = true; // Create a follow camera ThirdPersonCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("PlayerCamera")); ThirdPersonCameraComponent->AttachTo(ThirdPersonCameraBoom, USpringArmComponent::SocketName); // Set First Person Mesh Mesh1P = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->RelativeLocation = FVector(0.f, 0.f, -150.f); Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; Mesh1P->bOnlyOwnerSee = true; Mesh1P->SetIsReplicated(true); // Set Third Person Mesh GetMesh()->SetOwnerNoSee(true); GetMesh()->AttachParent = RootComponent; GetMesh()->bCastDynamicShadow = true; GetMesh()->CastShadow = true; GetMesh()->bOwnerNoSee = true; GetMesh()->SetIsReplicated(true); }
ABETCharacter::ABETCharacter() { // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // set our turn rates for input BaseTurnRate = 45.f; BaseLookUpRate = 45.f; // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->AttachParent = GetCapsuleComponent(); FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 64.f); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn) Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P")); Mesh1P->SetOnlyOwnerSee(true); // Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->AttachParent = FirstPersonCameraComponent; Mesh1P->bCastDynamicShadow = false; Mesh1P->CastShadow = false; // Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P are set in the // derived blueprint asset named MyCharacter (to avoid direct content references in C++) lightIntensity = 15000.f; flashLight = CreateDefaultSubobject<USpotLightComponent>(TEXT("Flashlight")); flashLight->SetIntensity(lightIntensity); flashLight->SetAttenuationRadius(2000.0f); flashLight->bVisible = true; flashLight->AttachParent = FirstPersonCameraComponent; walkSpeed = 300; runSpeed = 600; MAXSTAMINA = 10; widgetChecker = 0; stamina = MAXSTAMINA; running = false; power = true; Key = false; canLeave = false; }
// Sets default values ACarcinusCharacter::ACarcinusCharacter() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; static ConstructorHelpers::FObjectFinder<UBehaviorTree> BehaviorTree_obj(TEXT("BehaviorTree'/Game/AI/CarcinusCrab/BT_Carcinus.BT_Carcinus'")); if (BehaviorTree_obj.Object) { BehaviorTree = BehaviorTree_obj.Object; } /*Assign Carcinus Mesh*/ static ConstructorHelpers::FObjectFinder<USkeletalMesh> SkeletalMesh_body(TEXT("SkeletalMesh'/Game/Art/CarcinusCrab/CarcinusCrab.CarcinusCrab'")); if (SkeletalMesh_body.Object){ GetMesh()->SetSkeletalMesh(SkeletalMesh_body.Object); GetMesh()->SetRelativeLocation(FVector(-80.0f, 0.0f, -100.0), false); GetMesh()->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f),false); GetMesh()->SetRenderCustomDepth(true); GetMesh()->CustomDepthStencilValue = 0; GetCapsuleComponent()->InitCapsuleSize(60.0f, 100.0f); } ParticleComponent = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("ParticleSystemComp")); static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleObj(TEXT("ParticleSystem'/Game/Art/ParticleSystem/Blood/PAR_BloodCloud.PAR_BloodCloud'")); if (ParticleObj.Object) { ParticleComponent->Template = ParticleObj.Object; ParticleComponent->AttachTo(RootComponent); } HeadCollider = CreateDefaultSubobject<USphereComponent>(TEXT("HeadCollider")); HeadCollider->AttachTo(GetMesh(), TEXT("HeadSocket"), EAttachLocation::SnapToTarget, true); HeadCollider->SetCollisionProfileName(TEXT("Pawn")); HeadCollider->InitSphereRadius(4.0f); HeadCollider->bDynamicObstacle = 1; HeadCollider->CanCharacterStepUpOn = ECanBeCharacterBase::ECB_No; /* Range Collider Initialization */ RangeCollider = CreateDefaultSubobject<USphereComponent>(TEXT("RangeSphereCollider")); RangeCollider->InitSphereRadius(1000.0f); RangeCollider->AttachTo(RootComponent); RangeCollider->SetCollisionProfileName(TEXT("Spectator")); RangeCollider->SetVisibility(true); RangeCollider->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); /*Assign the Carcinus Animation Blueprint*/ static ConstructorHelpers::FObjectFinder<UAnimBlueprint> AnimBP_obj(TEXT("AnimBlueprint'/Game/Art/CarcinusCrab/Animations/CarcinusCrab_AnimBP.CarcinusCrab_AnimBP'")); if (AnimBP_obj.Object) { GetMesh()->SetAnimInstanceClass(AnimBP_obj.Object->GeneratedClass); } GetCharacterMovement()->MaxWalkSpeed = 200.0f; GetCharacterMovement()->MaxAcceleration = 500.0f; mEnemyMaxHealth = mEnemyHealth = 3; }