Door Dont Move

Hi I mad like in the lesson but my door didnt open, and i dont have any issue in logs.
My code:
OpenDoor.cpp

// Created by Dekar

#include "OpenDoor.h"

#include "GameFramework/Actor.h"

// Sets default values for this component's properties

UOpenDoor::UOpenDoor()

{

    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features

    // off to improve performance if you don't need them.

    PrimaryComponentTick.bCanEverTick = true;

    // ...

}

// Called when the game starts

void UOpenDoor::BeginPlay()

{

    Super::BeginPlay();

    InitialYaw = GetOwner()->GetActorRotation().Yaw;

    CurrentYaw = InitialYaw;

    TargetYaw += InitialYaw;

}

// Called every frame

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

{

    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    if (PressPlate->IsOverlappingActor(ActorThatOpens))

    {

        OpenDoor(DeltaTime);

    }

        

}

void UOpenDoor::OpenDoor(float DeltaTime)

{

    // UE_LOG(LogTemp, Warning, TEXT("%s"), *GetOwner()->GetActorRotation().ToString());

    // UE_LOG(LogTemp, Warning, TEXT("Yaw is: %f"), GetOwner()->GetActorRotation().Yaw);

    CurrentYaw = FMath::Lerp(CurrentYaw, TargetYaw, DeltaTime * 0.5f);

    FRotator DoorRotation = GetOwner()->GetActorRotation();

    DoorRotation.Yaw = CurrentYaw;

    GetOwner()->SetActorRotation(DoorRotation);

}

OpenDoor.h

// Created by Dekar

#pragma once

#include "CoreMinimal.h"

#include "Components/ActorComponent.h"

#include "Engine/TriggerVolume.h"

#include "OpenDoor.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )

class BUILDING_ESCAPE_API UOpenDoor : public UActorComponent

{

    GENERATED_BODY()

public: 

    // Sets default values for this component's properties

    UOpenDoor();

protected:

    // Called when the game starts

    virtual void BeginPlay() override;

public: 

    // Called every frame

    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

    void OpenDoor(float DeltaTime);

private:

    float InitialYaw;

    float TargetYaw;

    UPROPERTY(EditAnywhere)

    float CurrentYaw = 90.f;

    UPROPERTY(EditAnywhere)

    ATriggerVolume* PressPlate;

    UPROPERTY(EditAnywhere)

    AActor* ActorThatOpens;     

};


1 Like

okey now new problem, how to reset VS code because he doesnt show me now any problems?))

There are no errors in either screenshot.

  • Do you have the component attached to a door?
  • Does that component have a trigger volume selected?
  • Are you sure you ejected during play and selected the player as the actor that opens?
  • Are you sure you are in the trigger volume during play?

yep do all like in the video, I think problem in VSCode you can see in the top I move semicolon but VS dont show any problem.
and when use eject current Yaw was 0, i think it is problem too

If you compiled successfully then any “errors” in VS Code is a false positive. Would you mind sending me your project?

File > Package Project > Zip Up Project

Then upload it somewhere like Google Drive and link it here.

Yea sure,
https://drive.google.com/file/d/1WVNnKaC4197Aaoc-65A-GN4GFvZpBJOF/view?usp=sharing

I think you haven’t set the target yaw yet. You are saying TargetYaw += InitialYaw in the cpp file so it is staying at 0 when you lerp it.
You can try…
TargetYaw = InitialYaw + 90.f

This means it will get the initial yaw which is your initial door rotation and add it by the value you want… eg. 90.f so its going to be 0 + 90.

You can set any value… This is if you want to open it 90 degrees.

Also your CurrentYaw is exposed in blueprints as 0.f which will over write the cpp one which gets it at begin play so its better not to expose it anymore and dont initialize it as 90.f in header file as in the begin play it will change to InitialYaw.

Yeah, I’m blind you have set and exposed CurrentYaw instead of TargetYaw. It should be this way round.

UPROPERTY(EditAnywhere)
float TargetYaw = 90.f;

float CurrentYaw;

Yea it is work!!!
Thanks all, sory for long respons)

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

Privacy & Terms