Unreal Engine 4 http://uengine.ru/forum/ |
|
Передвижение персонажа в 2D на C++ http://uengine.ru/forum/viewtopic.php?f=19&t=12955 |
Страница 1 из 1 |
Автор: | Hope [ 13 янв 2018, 12:03 ] |
Заголовок сообщения: | Передвижение персонажа в 2D на C++ |
Привет всем! Такой вопрос: как сделать управляемое передвижение персонажа, так, чтобы управление осуществлялось с помощью стандартных клавиш WASD. Заранее спасибо! Тот код что есть, не работает. // Fill out your copyright notice in the Description page of Project Settings. #include "Camera.h" #include "GameFramework/SpringArmComponent.h" #include "GameFramework/Character.h" #include "Camera/CameraComponent.h" // Sets default values ACamera::ACamera() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; MyRootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootModel")); RootComponent = MyRootComponent; CameraSpring = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring")); CameraSpring->SetRelativeLocation(FVector(0, 0, 0)); CameraSpring->AttachToComponent(MyRootComponent, FAttachmentTransformRules::KeepRelativeTransform); MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); MyCamera->AttachToComponent(CameraSpring, FAttachmentTransformRules::KeepRelativeTransform); // MyCamera->AttachTo(CameraSpring, USpringArmComponent::SocketName); CameraSpring->SetRelativeRotation(FRotator(-90.f, 0, 0)); CameraSpring->TargetArmLength = 300.f; CameraSpring->bDoCollisionTest = false; AutoPossessPlayer = EAutoReceiveInput::Player0; } // Called when the game starts or when spawned void ACamera::BeginPlay() { Super::BeginPlay(); AddSpacemanToMap(); } // Called every frame void ACamera::Tick(float DeltaTime) { Super::Tick(DeltaTime); } // Called to bind functionality to input void ACamera::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis("Moving", this, &ACamera::FMove); } void ACamera::FMove(float ButVal) { int Key = ButVal; FVector2D WSAD; switch (Key) { case 1: WSAD = FVector2D(0, 0); WSAD.Y = 1; break; case 3: WSAD = FVector2D(0, 0); WSAD.X = 1; break; case 4: WSAD = FVector2D(0, 0); WSAD.X = -1; break; } if (MySpaceman) { MySpaceman->DirectionMoveSpaceman = &WSAD; } } void ACamera::AddSpacemanToMap() { FVector PlayerStart = GetActorLocation(); FRotator PlayerStartRotation = GetActorRotation(); if (GetWorld()) { MySpaceman = GetWorld()->SpawnActor<ASpaceman>(PlayerStart, PlayerStartRotation); } } |
Страница 1 из 1 | Часовой пояс: UTC + 3 часа |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |