How to reduce value back to original value if its bigger/smaller?

I’m trying to figure out how to create a motorcycle that plays like a motorcycle. (Non-physics objects). I’m trying to add the self-righting where the bike returns to its straight state after being leaned.

Right now I’m rotating it on the Y axis (pitch) when pressing left/right (A/D). I guess the approach would look something like: tick event → “If y_rotation>0 then y_rotation -=1” and “if y_rotation<0 then y_rotation+=1”, to put it very simple. But I have no idea to set this up with blueprints.

Knowing how to reduce a value back to the original number would be really useful for a lot of scenarios so it would be cool if someone could help me how to do this.

PS: If you have a better suggestion for how to do this self-uprighting of the bike, let me know. But I’d also really like to know how to get a number reduced back to its original number. :slight_smile:

Thanks in advance!

Check out the RInterp To and RInterp To Constant functions. You can probably get the functionality you need from those or a Lerp Function. Just input your current and target rotations, the delta time, and the speed you want to interpolate. Then set that rotation to the actor or component each frame.

If those ones don’t do exactly what you want, check out the Lerp functions for slightly different controls. All of these should work with Rotators, Vectors, and Floats, so they are pretty useful in many cases.

Hey, thanks so much for this headsup. I’ve played around with it but the best I can accomplish is having it turn to the new rotation (40 on the x axis for example) right in the beginning. Replicating your screenshot results in nothing at all happening.

Basically I would like it to just turn the bike back to its standard rotation while not pressing the A or D key. The example in your screenshot looks like it should do this (though constantly) but it doesn’t when I try it.

I uploaded both parts of my motorcycle event graph blueprint, maybe you see something obviously wrong? (I’ve annotated it a little to make sense quicker)

Does anyone have any idea what’s wrong? I feel like it’s close but I can’t seem to figure out the final piece of the puzzle.

Looks like in your first image you are setting actor rotation, but in the second one you are setting the component rotation on Mesh Rotation. You’ll want to make sure you are consistent in which rotations you’re setting.

I had a self righting spaceship in my game that would “roll” during turns which is the same type of movement as a “lean” on a motorcycle. This was my set-up. So what is happening here is I have a Timeline “Reset Roll” that has a float track from 0-1 over 2 seconds (or however long you would like the self-righting to take place). When this mechanism is called it gets the current rotation of the controller, and based on the value of that determines if it was a left or right sided roll (this is the select float node) I then use that value as the “B” input on the LERP node with the “A” input being the current controller’s “roll”. The alpha is set by the timeline which gradually interpolates from 0-1 over the 2 seconds. I then use the timeline “Update” execution to continuously and gradually set the roll of the controller back to 0 degrees from its current. Once this is complete I stop the timeline execution. Hope this helps.