- 【UE4】Unreal Engine 4 初心者質問スレッド part6
276 :名前は開発中のものです。[]:2019/12/14(土) 01:59:39.13 ID:uNgHVJ3i - void APlayerControllerBase::BeginPlay(){
Character = GetCharacter(); InputComponent = Character->FindComponentByClass<UInputComponent>(); MovementComponent = Character->GetCharacterMovement(); SetupInputComponent(); } void APlayerControllerBase::SetupInputComponent(){ InputComponent->BindAxis("MoveForward", this, &APlayerControllerBase::MoveForward); InputComponent->BindAxis("MoveRight", this, &APlayerControllerBase::MoveRight); InputComponent->BindAxis("TurnRate", this, &APlayerControllerBase::TurnAtRate); InputComponent->BindAxis("LookUpRate", this, &APlayerControllerBase::LookUpAtRate); } void APlayerControllerBase::MoveForward(float Value){ const FRotator Rotation = GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); Character->AddMovementInput(Direction, Value); } void APlayerControllerBase::MoveRight(float Value){ const FRotator Rotation = GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); Character->AddMovementInput(Direction, Value); } void APlayerControllerBase::TurnAtRate(float Rate){ CharacterIns->AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds()); } void APlayerControllerBase::LookUpAtRate(float Rate){ CharacterIns->AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds()); }
|