Rotating script suddenly stops working & detecting stop angle

Hi,

I’ve got a piece of script working where you click and hold on one object, and it will rotate, along with a second at a separate rate. Think a small wheel turning a bigger one, which moves slower.

The problem with it is that it works perfectly for a while, then suddenly stops, usually after 5 or 6 clicks and I can’t see why. It’s probably something simple, but I can’t spot it.

I also need the script to detect if the target is turned 180 degrees (or close enough to it), but with the previous problem haven’t been able to test it properly yet.

    var targetToRotate : GameObject;
    var parentRotateSpeed: int = 100;
    var rotateSpeed: int = 50;
    
    var activated: boolean = false;
    var ableToDoSomething:boolean = false;
    
    function Start () { }
    
    function Update () {
    	if(activated){
    		this.transform.Rotate(Vector3.right * Time.deltaTime * parentRotateSpeed);
    		targetToRotate.transform.Rotate(Vector3.right * Time.deltaTime * rotateSpeed);
    	}
    }
    function OnMouseDown():void
    {
    	activated = true;
// Detect when the target to rotate is NOT 180degrees

if(targetToRotate.transform.rotation.x <= 0.8){
    		Debug.Log("False: "+targetToRotate.transform.rotation.x);
    		// ableToDoSomething = false;
    	}

    }
    function OnMouseUp():void
    {
    	activated = false;
    
    // Detect when the target to rotate is 180degrees
    	if(targetToRotate.transform.rotation.x > 0.8){
    		Debug.Log("True: "+targetToRotate.transform.rotation.x);
    		// ableToDoSomething = true;
    	}
    }

One other thing, does anyone know of a good tutorial or method for keeping the mouse in the centre whilst retaining free movement similar to the default FPS view? Currently whilst trying to click the mouse moves all the way across the screen and things are harder to click.

Thanks.

Hi,

So as to close this question and in case anything similar comes up like this again, it now appears that the problem only appears with capsules, which I was using as my test objects.

Other primitives and meshes I’ve tried work fine. (Wish I’d thought to test that before…)

A work-around for the capsule is to add a mesh renderer rather than the default capsule render. Really frustrating to find, but there it is.

Now on to finding the best way for integrating fps movement! :slight_smile: