rotation

cover 2

Welcome to PlugPea, where we bring you useful tips and tricks for your Unity game development journey. In this post, we will showcase a rotation script that allows you to effortlessly adjust the rotation of your game object by manipulating intuitive sliders. By the end of this tutorial, you’ll be able to fine-tune your game object’s rotation and achieve the desired results quickly and efficiently.

To begin, you’ll need to download the “RangePlus” attribute. This attribute expands upon the functionality of the default range slider in Unity, allowing you to define the minimum and maximum rotation values for the X, Y, and Z axes. Once you have the attribute, you’re ready to dive into the script.

RangePlus attribute

Script Walkthrough

Let’s take a closer look at the C# code powering this rotation script. The default slider ranges from -90 to 90 degrees, ensuring a smooth rotation within that interval. If you prefer not to use the “RangePlus” attribute, you can simply delete it and rely on the default slider range provided by Unity, which spans from 0 to 1.

default slider ranges

By default, the rotation values for the X, Y, and Z axes are set to zero. The script introduces two important vectors: “lastRotation” and “lastAdjustment.” The “OnValidate” function is triggered whenever a slider in the inspector is modified.

lastRotation and lastAdjustment

The “DeltaAdjustment” variable represents the difference between the current adjustment and the previous adjustment. We utilize this delta adjustment to define the transform rotation, enabling smooth and precise rotation of your game object.

DeltaAdjustment

Implementing the Script

Now that we have covered the inner workings of the rotation script let’s apply it to your game object. In Unity, search for “Rotation” and add the script to your desired object. Once added, you can start manipulating the sliders to witness the immediate changes in rotation.

Rotation

The simplicity of this script lies in its user-friendly interface. Rather than manually adjusting the transform position by clicking and dragging, these sliders provide a more efficient method for modifying the rotation. You can effortlessly fine-tune the rotation of your game object by adjusting the sliders to your liking.

Achieving Your Desired Rotation

Continue tweaking the sliders until you find the optimal rotation for your project. If you ever wish to reset the rotation to its default values, you can easily do so with a single click. The script empowers you to experiment, iterate, and ultimately achieve the best rotation for your game object.

Desired Rotation

Conclusion

We hope you found this blog post helpful in your game development endeavors.

You can use this free unity asset to tweak the rotation of your game object easily. Simply add the rotation script to your game object, and now you can change the rotation by changing the rx, ry, and rz in the inspector. Be sure to also add the RangePlusAttribute to your project, as it will help you to change the minimum and maximum value of the sliders inside the inspector without needing you to edit the script manually.

Download Rotation

Download RangePlus

 

Related Articles

Position

In the world of game development, precise object positioning is crucial for creating immersive and dynamic experiences. Thankfully, Unity provides a range of tools and…

Responses

Your email address will not be published. Required fields are marked *