Premise : Sorry for my “google translator” english
Hi , i want to be able to move my pawn using his forward vector , so when the pawn rotate, his vector used for movement should rotate too.
This is the code , but i get error at this line :
CurrentVelocity.Rotation = FMath::Clamp(YawValue, -1.0f, 1.0f) * 100.0f;
saying " ‘=’ failed to function as left operand"
The Rotation controls work fine , as the movement along the X axis , but i can’t get that axis to rotate when i press the “rotate buttons”.
This is the code:
Test01Pawn.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "TutorialTestProject.h"
#include "Test01Pawn.h"
// Sets default values
ATest01Pawn::ATest01Pawn()
{
// 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;
// Set this pawn to be controlled by the lowest-numbered player
AutoPossessPlayer = EAutoReceiveInput::Player0;
// Create a dummy root component we can attach things to.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
// Create a camera and a visible object
UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
// Attach our camera and visible object to our root component. Offset and rotate the camera.
OurCamera->SetupAttachment(RootComponent);
OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
OurVisibleComponent->SetupAttachment(RootComponent);
}
// Called when the game starts or when spawned
void ATest01Pawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATest01Pawn::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
// Handle movement based on our "MoveX" and "MoveY" axes
if (!CurrentVelocity.IsZero())
{
FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
SetActorLocation(NewLocation);
}
//Handle Rotation
if (!CurrentRotator.IsZero())
{
FRotator NewRotation = GetActorRotation() + (CurrentRotator * DeltaTime);
SetActorRotation(NewRotation);
}
}
// Called to bind functionality to input
void ATest01Pawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis("MoveForward", this, &ATest01Pawn::MoveForward);
InputComponent->BindAxis("Rotate", this, &ATest01Pawn::Rotate);
}
void ATest01Pawn::Rotate(float YawValue)
{
CurrentRotator.Yaw = FMath::Clamp(YawValue, -1.0f, 1.0f) * 100.0f;
CurrentVelocity.Rotation = FMath::Clamp(YawValue, -1.0f, 1.0f) * 100.0f;
}
void ATest01Pawn::MoveForward(float AxisValue)
{
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f;
}
Test01Pawn.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "Test01Pawn.generated.h"
UCLASS()
class TUTORIALTESTPROJECT_API ATest01Pawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ATest01Pawn();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(EditAnywhere)
USceneComponent* OurVisibleComponent;
// Input functions
void MoveForward(float AxisValue);
void Rotate(float YawValue);
//Input Variables
FVector CurrentVelocity;
FRotator CurrentRotator;
};