Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Can't seem to get Absolute Rotation to Work in C++
Post Flair (click to view more posts with a particular flair)
Post Body

So I'm currently working on a 2D shooter for a school project, and I am working on the enemies. I've added a widget component to them that displays their health, but whenever they begin moving and chasing after the player the healthbar rotates along with them. So I figured I'd add another empty scene component to them to serve as a sort of "widget root," that would have its rotation set to absolute so it would follow the enemy but not rotate with them, then attach the health bar to that. However, it doesn't work. At least, it doesn't work for the widget. Adding things in after the fact, like a cube via the blueprint editor, works fine, they keep their rotation, but the widget continues to rotate despite sharing the same parent component as the cube. I don't understand what is going wrong, did I set something up incorrectly? What about the cube results in it working properly?

Here's my declaration code for the widget root and the widget.

EDIT: I've managed to get it so the widget does not rotate, but it still moves around, as if the root is still rotating but the widget has absolute rotation, which is not at all what I coded.

WidgetRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Widget Root"));
WidgetRoot->SetupAttachment(GetRootComponent());
WidgetRoot->Mobility = EComponentMobility::Movable;
WidgetRoot->SetAbsolute(false, true, false);
WidgetRoot->SetRelativeRotation(FRotator(0, 0, 0));

//Adds Health Bar
HealthWidgetComp = CreateDefaultSubobject<UWidgetComponent>(TEXT("Health Bar"));
static ConstructorHelpers::FClassFinder<UUserWidget>hudWidgetObj(TEXT("/Game/MyStuff/EnemyHBar_CPP"));

if (hudWidgetObj.Succeeded()) {
HudWidgetClass = hudWidgetObj.Class;
}
else {
HudWidgetClass = nullptr;
}

HealthWidgetComp->SetWidgetClass(HudWidgetClass);
HealthWidgetComp->Mobility = EComponentMobility::Movable;
HealthWidgetComp->SetupAttachment(WidgetRoot);
HealthWidgetComp->SetDrawSize(FVector2D(100, 50));

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,894
Link Karma
5,368
Comment Karma
4,452
Profile updated: 1 week ago
Posts updated: 2 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 months ago