Hi there,
As the title suggests, I would like to rotate a platform (that balls bounce off). At the moment it rotates, but is uncomfortable as the platform rotation is equal to the Input.mousePosition.x.
eg. When I would like the move the platform 20degrees, the mouse.x will be at 175, and I need to make is 20 so that it rotates correctly.
Here is the code.
var lastMousePosition : Vector3;
private var shouldRotate:boolean;
function Start(){
shouldRotate=false;
}
function Update() {
Debug.Log(Input.mousePosition);
}
function FixedUpdate(){
if(shouldRotate){ //If shouldRotate = true...
if(Input.GetMouseButton(0)){ //and if MouseButton is clicked
if(Input.GetMouseButtonDown(0)){ //and held down
//reset
lastMousePosition = Input.mousePosition;
}
else {
transform.root.transform.Rotate(0,0,Input.mousePosition.x - lastMousePosition.x);
}
lastMousePosition = Input.mousePosition;
}
}
}
function OnMouseUp(){
shouldRotate=false;
}
function OnMouseDown(){
shouldRotate=true;
}