Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#CodeDrop: Rotation To Mouse Tracking

Rotation To Mouse Tracking

Difficulty: ★★☆☆☆

Scalability: ★★☆☆☆

Usage: Put this script on an object, and it will rotate based on the mouse cursors's screen position. There are 2 modes, ClickDrag, and not ClickDrag. ClickDrag, you will need to have set a mouse button, and click and drag it. Not ClickDrag, the object will just rotate based on the cursors position relative to the center of the screen. Both methods use the 'DeadZone' value, which is a distance in pixels the cursor needs to have moved, either from center or its last position, for rotation to happen. You can also set an 'Anchor' for the object to rotate AROUND. All controls are still based on cursors screen position, and the object will always face towards it's anchor.

Notes: This was based on an older script I wrote, but I cleaned it up a bit and made sure it worked. If you wanted to make any changes like rotation speed or dead zone size, there are variables for things like that. I wouldn't try to add any more functionality to it, but you could add things to the rotation part of it, like limits. For ClickDrag, I recommend you set the dead zone to 0. For not ClickDrag, the camera will continue to rotate until the cursor is back in the dead zone. The cursor doesn't move towards the screen center on it's own, so if you wan't that, you'll have to add it, otherwise to stop, you need to put the cursor back in the center.

look out below


Best Answer

Sign In or Register to comment.