Rotation Module - Make Rotating Models & Parts Easy!

I have found that rotating parts, and particularly models, can be troublesome at times. Especially when you want to do rotations above 180* going in a specific direction, or a 360 degree rotation. I know that in my experience, the amount of code it takes to take care of all of that is a little frustrating. It’s not a huge amount, but it’s enough to where we should change that.

Introducing, the rotation module. With this module, you can simply call :rotateItem(instance,propertyTable) and customize it as much as you’d like. Certainly helps to clean and speed things up a bit, especially if you’re doing a lot of them!

Below is an example usage. Note that you do not need to define all properties, as they will default to the values that are below.

local module = require(workspace.rotationHandler)
module:rotateItem(workspace.Car,{
		["rotationDegrees"] = 360 , -- The amount you want the object to be rotated.
		["rotationAxis"] = "Y", -- The axis to rotate.
		["rotationTime"] = 5, -- The amount of time one full rotation takes to complete.
		["rotationCondition"] = function() return 1000000 end, -- Conditional statement/countdown. For countdowns, this is your timer. Otherwise, your conditional statement goes here. 
		["rotationConditionType"] = "countdown", -- Set this to 'countdown' if you want it to end on a timer. For infinite rotation, just put it at a high value.
		["reverseWhenFinished"] = false, -- Whether the object reverses back to it's starting position at the end of each rotation.
		["easingStyle"] = Enum.EasingStyle.Linear,
		["easingDirection"] = Enum.EasingDirection.In
}
9 Likes

Why have so many parameters in the function, when you can handle stuff such as “isModel” in the code, by checking the type of the first parameter.

As I said, not all of them need to be filled out, they will default to a certain value if not specified. I don’t think having little to no parameters would be wise, because then you would be able to customize very little.

I don’t want people to supply their own TweenInfo because it could interfere with things, like the reversing for example. I have a custom reverse inside there, because if you have to do more than 1 rotation to achieve the desired degree of rotation, the reverse will not function properly. Instead, it would reverse that one rotation, instead of the entire set of rotations.

Thanks for the suggestion on the isModel parameter, I’ve updated it to no longer require input on that.

2 Likes

I’d recommend showing in the example if parameter is optional or required.