UnrealScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a Player that is in third person with W, A, S, D controls"
// Create a Player APlayer::APlayer() { // 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; // Set the size of our collision capsule. GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // Create a camera boom attached to the root (capsule) CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does CameraBoom->TargetArmLength = 500.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 and attach to boom SideViewCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("SideViewCamera")); SideViewCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); SideViewCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm // 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; } // Called to bind functionality to input void APlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); // Set up gameplay key bindings check(PlayerInputComponent); PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump); PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping); PlayerInputComponent->BindAxis("MoveRight", this, &APlayer::MoveRight); } void APlayer::MoveRight(float Value) { // add movement in that direction AddMovementInput(FVector(0.f,-1.f,0.f), Value); }