Beginner - Clamping the X axis value

Hi all, So i’m trying to do something rather simple, move my Actor ( bucket ) along the X axis whilst having the x axis clamped between the values -90.f and 90.f.
So here is my code…


XMovement = GetInputAxisValue("MoveHorizontal") * 20.f * DeltaTime;
    Bucket->AddLocalOffset(FVector(XMovement, 0.f, 0.f));
    FMath::Clamp<float>(Bucket->GetComponentLocation().X, -90.f, 90.f); 

I’ve tried different variations of it, for example updating the x axis to equal a variable and then clamping that. however this was quite obviously a fail.
So can someone please tell me why im being an idiot and cant figure this out ?

Thank you !!!

You’re clamping a temporary copy of x. Clamp it before setting it.

Edit: just to be clearer, you’re not assigning the clamped result to anything. Make sure to update the bucket’s x coordinate.

ah i see, i had a feeling it was something simple, thank you for the reply :slight_smile: