ACameraSampleCharacter::ACameraSampleCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Don't rotate character to camera direction bUseControllerRotationPitch = false; bUseControllerRotationYaw = true; bUseControllerRotationRoll = false; // Disable Jump and Duck actions bAddDefaultMovementBindings = false; // Create a camera boom... CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->AttachTo(RootComponent); CameraBoom->bAbsoluteRotation = false; CameraBoom->TargetArmLength = 800.f; CameraBoom->SetRelativeRotation(FRotator(-60.f, 0.f, 0.f)); CameraBoom->bDoCollisionTest = false; CameraBoom->bUsePawnControlRotation = false; CameraBoom->bInheritPitch = false; CameraBoom->bInheritRoll = false; CameraBoom->bInheritYaw = true; CameraBoom->bEnableCameraLag = true; CameraBoom->bEnableCameraRotationLag = true; // Disable collisions GetCollisionComponent()->bGenerateOverlapEvents = false; GetCollisionComponent()->SetCollisionProfileName("NoCollision"); // Create a camera... TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera")); TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName); TopDownCameraComponent->bUsePawnControlRotation = false; }
ASrPlayerPawn::ASrPlayerPawn() { GetCollisionComponent()->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); bAddDefaultMovementBindings = false; CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent")); if (CapsuleComponent) { CapsuleComponent->InitCapsuleSize(0.0f, 0.0f); CapsuleComponent->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); CapsuleComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); CapsuleComponent->CanCharacterStepUpOn = ECB_No; CapsuleComponent->bShouldUpdatePhysicsVolume = false; CapsuleComponent->bCheckAsyncSceneOnMove = false; CapsuleComponent->SetCanEverAffectNavigation(false); CapsuleComponent->bDynamicObstacle = false; SetRootComponent(CapsuleComponent); } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Capsule Component in %s"), *GetName()); } // Create a camera boom (pulls in towards the player if there is a collision) CameraBoomComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); if (CameraBoomComponent) { CameraBoomComponent->SetupAttachment(RootComponent); CameraBoomComponent->TargetArmLength = 30000.0f; // The camera follows at this distance behind the character CameraBoomComponent->bUsePawnControlRotation = true; // Rotate the arm based on the controller CameraBoomComponent->bDoCollisionTest = false; } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Camera Boom Component in %s"), *GetName()); } CameraComponent = CreateDefaultSubobject<USrPlayerCameraComponent>("CameraComponent"); if (CameraComponent) { CameraComponent->SetupAttachment(CameraBoomComponent, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation CameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Camera Component in %s"), *GetName()); } }
ASpectatorPawn::ASpectatorPawn(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer .SetDefaultSubobjectClass<USpectatorPawnMovement>(Super::MovementComponentName) .DoNotCreateDefaultSubobject(Super::MeshComponentName) ) { bCanBeDamaged = false; //SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy); //bReplicates = true; BaseEyeHeight = 0.0f; bCollideWhenPlacing = false; SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; static FName CollisionProfileName(TEXT("Spectator")); GetCollisionComponent()->SetCollisionProfileName(CollisionProfileName); }
AMeasurementGate::AMeasurementGate(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UBoxComponent>(TEXT("CollisionComp"))) { UBoxComponent* BoxCollisionComponent = CastChecked<UBoxComponent>(GetCollisionComponent()); BoxCollisionComponent->ShapeColor = TriggerBaseColor; BoxCollisionComponent->InitBoxExtent(FVector(40.0f, 40.0f, 40.0f)); static FName CollisionProfileName(TEXT("Trigger")); BoxCollisionComponent->SetCollisionProfileName(CollisionProfileName); if (GetSpriteComponent()) { GetSpriteComponent()->AttachParent = BoxCollisionComponent; } OnActorBeginOverlap.AddDynamic(this, &AMeasurementGate::OnBeginOverlap); }
void CCar::InitCar( CGeneralManager* p_obj_man, Script::CStruct* pNodeData ) { p_obj_man->RegisterObject(*this); MovingObjectCreateComponents(); uint32 skeletonName = CRCD(0x88c21962,"car"); bool use_skeletal_cars = false; if ( pNodeData->GetChecksum( CRCD(0x09794932,"skeletonName"), &skeletonName, false ) ) { use_skeletal_cars = true; } if ( use_skeletal_cars ) { // m_model_restoration_info.mSkeletonName=skeletonName; // component-based Dbg_MsgAssert( GetSkeletonComponent() == NULL, ( "Skeleton component already exists" ) ); Script::CStruct* pSkeletonStruct = new Script::CStruct; pSkeletonStruct->AddChecksum( CRCD(0xb6015ea8,"component"), CRC_SKELETON ); pSkeletonStruct->AddChecksum( CRCD(0x222756d5,"skeleton"), skeletonName ); this->CreateComponentFromStructure(pSkeletonStruct, NULL); delete pSkeletonStruct; #ifdef __NOPT_ASSERT__ Gfx::CSkeleton* pSkeleton = GetSkeletonComponent()->GetSkeleton(); Dbg_Assert( pSkeleton ); Dbg_Assert( pSkeleton->GetNumBones() > 0 ); #endif } else { // m_model_restoration_info.mSkeletonName=0; } MovingObjectInit( pNodeData, p_obj_man ); Obj::CModelComponent* pModelComponent = new Obj::CModelComponent; this->AddComponent( pModelComponent ); pModelComponent->InitFromStructure( pNodeData ); Dbg_Assert( GetModel() ); // set up the skeleton for this car model, if any // needs to come after the geom is loaded (because // that's where the hierarchy info is) if ( use_skeletal_cars ) { const char* p_model_name; pNodeData->GetText( CRCD(0x286a8d26,"model"), &p_model_name, true ); // sanity check on number of bones in skeleton Dbg_MsgAssert( GetModel()->GetNumObjectsInHierarchy()==GetSkeleton()->GetNumBones(), ( "Expected to find %d bones in the %s skeleton (found %d in %s - %s)", GetSkeleton()->GetNumBones(), Script::FindChecksumName( skeletonName ), GetModel()->GetNumObjectsInHierarchy(), Script::FindChecksumName( GetID() ), p_model_name ) ); GetCarPhysicsComponent()->init_car_skeleton(); } else { if ( GetModel()->GetNumObjectsInHierarchy()!=0 ) { uint32 name = 0; pNodeData->GetChecksum( CRCD(0xa1dc81f9,"name"), &name, Script::ASSERT ); Dbg_MsgAssert( 0, ( "Skeletal model requires a skeleton %s", Script::FindChecksumName(name) ) ); } } GetCarPhysicsComponent()->InitFromStructure( pNodeData ); if ( !pNodeData->ContainsFlag( CRCD(0x0bf29bc0,"NoCollision") ) ) { // GJ: collision component should be added after the model component, // because we want the same m_pos/m_matrix that is used for displaying // the model Dbg_MsgAssert( GetCollisionComponent() == NULL, ( "Collision component already exists" ) ); Script::CStruct* pCollisionStruct = new Script::CStruct; pCollisionStruct->AddChecksum( CRCD(0xb6015ea8,"component"), CRC_COLLISION ); pCollisionStruct->AddChecksum( CRCD(0x2d7e583b,"collisionMode"), CRCD(0x6aadf154,"geometry") ); this->CreateComponentFromStructure(pCollisionStruct, NULL); delete pCollisionStruct; } // designer controlled variables: // set defaults, to be overridden by script values if they exist: GetMotionComponent()->m_max_vel = ( MPH_TO_INCHES_PER_SECOND ( DEFAULT_CAR_MAX_VEL ) ); GetMotionComponent()->m_acceleration = FEET_TO_INCHES( DEFAULT_CAR_ACCELERATION ); GetMotionComponent()->m_deceleration = FEET_TO_INCHES( DEFAULT_CAR_DECELERATION ); // stick to ground tests against wheels, rather than origin // (eventually, we'll move this functionality into a custom // sticktoground component) GetMotionComponent()->m_point_stick_to_ground = false; GetMotionComponent()->EnsurePathobExists( this ); GetMotionComponent()->GetPathOb()->m_enter_turn_dist = FEET_TO_INCHES( DEFAULT_CAR_TURN_DIST ); // Add a NodeArrayComponent to the Car, so it will request loading of the associated node array. Obj::CNodeArrayComponent *p_node_array_component = new Obj::CNodeArrayComponent; this->AddComponent( p_node_array_component ); p_node_array_component->InitFromStructure( pNodeData ); if ( !pNodeData->ContainsFlag( CRCD(0x1fb9e477,"NoRail") ) ) { // Add a RailManagerComponent to the Car, so it can be used for grinding etc. Obj::CRailManagerComponent *p_rail_manager_component = new Obj::CRailManagerComponent; this->AddComponent( p_rail_manager_component ); p_rail_manager_component->InitFromStructure( pNodeData ); } if ( !pNodeData->ContainsFlag( CRCD(0x59793e2b,"NoSkitch") ) ) { // Add an ObjectHookManagerComponent to the Car, for use by the SkitchComponent. Obj::CObjectHookManagerComponent *p_object_hook_manager_component = new Obj::CObjectHookManagerComponent; this->AddComponent( p_object_hook_manager_component ); p_object_hook_manager_component->InitFromStructure( pNodeData ); // Add a SkitchComponent to the Car, so it can be used for skitching etc. Obj::CSkitchComponent *p_skitch_component = new Obj::CSkitchComponent; this->AddComponent( p_skitch_component ); p_skitch_component->InitFromStructure( pNodeData ); } // Finalize the object, saying we've added all the components Finalize(); // need to synchronize rendered model's position to initial world position GetModelComponent()->FinalizeModelInitialization(); SetProfileColor(0xc0c000); // cyan = car }