A way to open any door? also, getting confused about data types

Hi, while doing the challenge of this lesson I came across the Add function for the FRotator struct, and using it I wrote a code to open both of the doors of the example, regardless the rotation:

void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	float DoorRotation = +90.f;

	FRotator CurrentRotation = GetOwner() -> GetActorRotation();
	
	GetOwner() -> SetActorRotation(CurrentRotation.Add(0.f,DoorRotation,0.f));

}

Is this a good solution?
Also I’m getting confused with the way some things are declared.
sometimes I can use curly braces and sometimes not.
For example, when storing all the axis values in an FRotator I was able to use an array-declaration type, so: FRotator TargetRotation = {0.f,DoorRotation,0.f} worked well. However when trying to use the same syntax for the .Add function for the rotator I would’ve expected to be able to use: .Add({value1,value2,value3}); but that didn’t work.
even If I was giving it the TargetRotation like this: .Add(TargetRotation); that wouldn’t work neither.
I know I must be mixing concepts here, could you point me to what to look for to understand this better?
thank you!

It’s getting ahead of the course as relative rotations come in later :+1:.

That is specifically called “brace initializer-list” and you’re using it to initialise an FRotator.

Add is just a function taking 3 floats, using {} as you have means you’re trying to pass in a single type which would be a std::initializer_list<float> same goes for the other situation.

Thank you for your quick answers. This is really helping me to move forward with the course

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

Privacy & Terms