how to switch between if and else slowly or gradient way something like that, I don’t know how to describe it but I give an if to a rotation (with degree per second ) and when condition if goes to false, rotation doesn’t act base on degree per second and it jump.
if (GetSocketRotation("ProjectileSocket").Yaw <= 10 && GetSocketRotation("ProjectileSocket").Yaw >= -10)
SetRelativeRotation(FRotator(RawElavtion, 0, 0));
//before else it can to rotate to any pitch value but after that pitch clamp between 0, 40
auto ClampRawElavtion = FMath::Clamp<float>(RawElavtion, 0, 40);
SetRelativeRotation(FRotator(ClampRawElavtion, 0, 0));
I think there is something fundamentally wrong here.
If your value is out of the range [-10,10] you clamp it in the range [0,40] which means that everything below -10 will instantly go to 0 hence “the jump”.
I am not sure what you are trying to achieve here. Can you provide more specifics?
I want my object can rotate any Pitch degree between -10,10 Yaw range, its means Pitch value clamp between 0,40 range in Yaw 10,370 degree range [-10,10 backwards]
I get what you mean now. (I hope.)
- You have your Actor at, say, 60
degrees Pitch in the zone [-10,10]
Yaw as this zone Pitch is [-90, 90].
- You rotate your Yaw outside of that
zone, say at 20 degrees and your
Pitch is clamped at 40
You need that transition smoothed right?
Now you will have to decide how that smoothing is produced:
- Does the smoothing depend on the Yaw
angle - say ±10 Yaw: Pitch is free(±90);
±20 Yaw: Pitch is clamped at 0÷40; But at
±15 Yaw: Pitch is clamped somewhere in
the middle like -45÷65?
- …or does it depend on time - say
you’ve gust gone out of the free
range ±10 Yaw and now your Pitch will be
slowly reduced to fit in the 0÷40
range in the span of 5 seconds?
it would be perfect if you show me both ways in a case in the future I have more options to choose in a situation like this.
and it would even more perfect if show it with correcting my code.
Sounds like a job for Interpolation. Look up the interp functions. They give you a gradual change in value over time.
So can you show me how could i use it in my code ?
Basically have a class variable to set the rotation youre trying to gradually get to,
and the IF sets it to one thing and the ELSE sets it to another, and you can Interp from the current rotation toward that target rotation during the Tick function (using delta time to make it.consistent over different framerates)
have a read of these;
then just try using whichever seems best and see if it works