Hey there.
Doing the Obstacle Assault part of the course right now.
While playing around with the rotation platform and its speed, I came across this weird behavior:
(Implementation is the same as in the video)
When the rotation speed is set to exactly 360, the body does not seem to move at all.
I’m assuming that this is somehow due to 360° being a full circle, so equivalent to not rotating at all.
Is there any way around this?
Hey, thank you for your reply.
Unfortunately, being a beginner, I’m not quite sure what you mean by that. The function you linked seems to return an FRotator. Do you mean that I would need to feed the output of that function into the AddActorLocalRotation()? If so, what parameters would I need to feed into it to get the same behaviour as I have now? Unfortunately, the documentation is a bit lackluster when it comes to explaining what those parameters are supposed to do. Right now, it reads to me as if that would be a solution for having the platform turn into a specific direction, not one for having a constantly spinning one, as it is shown in the course video. Or am I misreading what that function does?
Excuse me as
- I misremembered VInterpTo (same thing but for vectors) being done in this section but its the one after.
- I’m not sure it would work anyway; that function takes the current rotation and a target rotation to interpolate to, along with a speed and delta time. You would typically use it with Get/SetActorRotation.
With that said I just tested Sam’s project and it seems to work fine with a value of 360. Could you show your code please?
My Code looks like this, I’ve kept multiple variants of things I tried, the one uncommented is the one the video closed with:
MovingPlatform.h-file (excerpt):
UPROPERTY(EditAnywhere, Category="Moving Platform")
FRotator PlatformRotationSpeed = FRotator(0.0, 0.0, 0.0);
MovingPlatform.cpp-file (excerpt):
void AMovingPlatform::RotatePlatform(float DeltaTime)
{
// Original implementation - doesn't work with 360, apparently also wonky due to wraparound
// FRotator CurrentRotation = GetActorRotation();
// CurrentRotation += PlatformRotationSpeed * DeltaTime;
// SetActorRotation(CurrentRotation);
// final implementation, apparently no wraparound wonkyness, but also no dice with 360
AddActorLocalRotation(PlatformRotationSpeed * DeltaTime);
// spelling it out to check if there is a difference - nope
// FRotator DeltaTurn = FRotator((PlatformRotationSpeed.Pitch * DeltaTime), (PlatformRotationSpeed.Yaw * DeltaTime), (PlatformRotationSpeed.Roll * DeltaTime));
// AddActorLocalRotation(DeltaTurn);
}
I also did a clueless deep dive into UE5s source code, but I didn’t see anything obvious.
Another thing that crossed my mind: Which version of UE are you testing it on?
Thanks so far!
5.3 though I highly suspect any of the code that’s used in AddActorLocalRotation
hasn’t been touched in quite a while.
To give perhaps a better test case, could you specify the starting rotation of the actor and the rotation velocity? (I did try 360 in all 3 axes and all worked fine with that code)
Thanks for your efforts!
I found the error and do feel tad stupid now.
In a session where I might not have been completely awake, I implemented something I inteded to prevent unnecessary calculations. Then I collapsed the Tick function in VS Code, so I didn’t see it anymore.
And then I forgot about it.
What I implemented:
if(!PlatformRotationSpeed.IsZero())
RotatePlatform(DeltaTime);
D’oh.
Lesson learned: coding works best if you can actually remember what you did.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.