Click and Drag to Rotate

How would I get a plane to rotate if I clicked and dragged?

What is your problem? Rotating or getting the mouse position?

Hold on ,ill post a web player

Pressing Up and Down rotates the scale. I want to be able to click and drag it, not have to press buttons. Graphics teacher requested this, and he requested that it be controlled by clicking and dragging.
http://www.maelstrom-racing.net/Resize%20Scale/Resize%20Scale/Resize%20Scale.html

Can be done with simple vector math.

Create two 2D vectors in screen space. One from screen center to top side (you can create this within start function as it will never change) and other from screen center to cursor position (within update). Get the angle between them and rotate the plane.

You can start by getting the width and height values of the screen and finding the center point.

I’ll be honest with you, I’m failing algebra…

bump< >.>

ok, here is the code I threw together. It works, but only for horizontal mouse movement. Mac OS X being used in this case.

var Speed : int;
var ReferencePointX : int;
var ReferencePointY : int;
var divider : int;
function FixedUpdate () {
	y = Speed * (Input.GetAxis("Vertical")) * Time.deltaTime;
	transform.Rotate(0, y, 0);
	
	if(Input.GetButtonDown("Fire1") || Input.GetButtonUp("Fire1")){
		ReferencePointX = Input.mousePosition.x;
		ReferencePointY = Input.mousePosition.y;
	}
	if(Input.GetButton("Fire1")){
		transform.rotation.y = (-(Input.mousePosition.x - ReferencePointX) + (Input.mousePosition.y - ReferencePointY))/divider;
	}
}

Transform.rotation is a quaternion, and you generally don’t want to modify its elements directly. Instead, use Transform.Rotate() (as you’re doing elsewhere in the code), use Transform.eulerAngles, or compute and assign a new orientation to the ‘rotation’ field.

I would use Input.GetAxis(“Mouse X”) and Input.GetAxis(“Mouse Y”) and then do with those whatever you want to rotate it.

Input.GetAxis(“mouse X”) returns the delta that the mouse has moved in a single frame. I don’t think that would be very useful in this situation.

A circular drag-to-rotate in screen space is actually very simple though.

On mouse down store vector from centre of screen to mouse coord. On Update get new mouse coord vector from centre of screen use Vector2.Angle to get drag offset and transform.Rotate() to apply dragging.

Use the vector2 class to store vectors. Vector2.Angle to get the angle, then transform.Rotate() to apply it.

Keep in mind screen space coordinates start from the edges not the centre.

Much help, I will try these next block. THEY HAVE MACS :smile:

Fixed. I used a different method. I made an empty gameobject that followed the mouse and stayed directly under it at all times. I then put a LookAt script on the top disc and…perfezione