Platform not moving

I am in the Obstacle Assault course and when I had the cube it was moving back to my player location and then when I implemented the Z axis logic in the tick function it would no longer move to where my player was but would move up. I am having a similar issue with getting the platform to spawn or jump next to my player character.

Could you show your code, and if it’s not too much trouble a video so we’re definitely on the same page?

Yes give me just a few seconds. I don’t know about the video but I will try.
Edited to show code
MovingPlatform.cpp:

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


#include "MovingPlatform.h"

// Sets default values
AMovingPlatform::AMovingPlatform()
{
 	// Set this actor 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 AMovingPlatform::BeginPlay()
{
	Super::BeginPlay();

}

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

	FVector LocalVector = MyVector;

	LocalVector.Z = LocalVector.Z + 1;

	MyVector.Y = MyVector.Y + 1;

	SetActorLocation(LocalVector);

	// Move platform forwards
		// Get current location
		// Add vector to that location
		// Set the location
	// Send platform back if gone too far
		// Check how far we've moved
		// Reverse direction of motion if gone too far

}

MovingPlatform.h:

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MovingPlatform.generated.h"

UCLASS()
class OBJECTASSAULT_API AMovingPlatform : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMovingPlatform();

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

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

	UPROPERTY(EditAnywhere)
	FVector MyVector = FVector(1, 2, 3);

	UPROPERTY(EditAnywhere)
	float MyX = 0;
};

I was able to figure this out. I had forgotten to copy the player location transform and paste it for the location transform of the MovingPlatform. Thank you.

1 Like

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

Privacy & Terms