Script C++ Movement

Hi, I’m new using Unreal, i’m doing some tutorials but now my script doens’t work

.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"

UCLASS()
class CAT_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AMyCharacter();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;


protected:

	void MoveForward(float AxisValue);
	void MoveRight(float AxisValue);
};

.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyCharacter.h"
#include "Logging/LogMacros.h"

// Sets default values
AMyCharacter::AMyCharacter()
{
 	// 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;

}

// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AMyCharacter::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AMyCharacter::MoveRight);
	PlayerInputComponent->BindAxis(TEXT("Turn"), this, &AMyCharacter::AddControllerYawInput);
	PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &AMyCharacter::AddControllerPitchInput);
}

void AMyCharacter::MoveForward(float AxisValue)
{
	AddMovementInput(GetActorForwardVector() * 10);
}

void AMyCharacter::MoveRight(float AxisValue)
{
	AddMovementInput(GetActorRightVector() * AxisValue);
}

The AddMovementInput(GetActorForwardVector() * 10); is just to check isn’t 0 AxisValue.

image

With my little knowledge apparently everything is all right.

do you mean it doesn’t compile?

It may be just the copy/paste into here, but your comment line “// Set this ch…” has a new line in it, and so it’s parsing the ’ as a quote…

I think MoveForward and MoveRight need to be declared as a UFUNCTION() in your header file.

So, the project is running but when I build in VS, that’s happen:

image

Microsoft.MakeFile.Targets(44,5): error MSB3073: The comman

But in the unreal is running fine, but when I tighten some axle, nothing happen (The player doesn’t move).

image
I made this, but nothing happened

So I put somo UE_LOG e dind’t work, so I notice the script I attach is wrong.
I Change and start work

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.