A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Rotating movie clip based on relative mouse movement

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    501

    Rotating movie clip based on relative mouse movement

    I am trying to get a movie clip to rotate smoothly based on the mouse movement. I dont want its rotation to be based on the angle of the cursor to the object but instead no matter where mouse is in relation to mc, I want it to rotate based on the movement of the mouse. So if you move cursor clockwise the mc rotates clockwise.

    Here is what i have so far

    Code:
    if (objGame == undefined) {
    	
    	objGame = new Object();
    	
    	objGame.lastX = _root._xmouse;
    	objGame.lastY = _root._ymouse;
    	
    	objGame.lastRotation = 0;
    }
    
    this.onMouseMove = function() {
    
    	if (_root._xmouse <> objGame.lastX or _root._ymouse <> objGame.lastY) {	
    		
    		var xDiff = _root._xmouse - objGame.lastX;
    		var yDiff = _root._ymouse - objGame.lastY;
    		
    		var numRotation = (Math.atan2(yDiff, xDiff)) * (180 / Math.PI);
    		
    		if (numRotation > objGame.lastRotation) {
    			
    			plane._rotation = plane._rotation + 10;
    			
    		} else if (numRotation < objGame.lastRotation) {
    			
    			plane._rotation = plane._rotation - 10;
    		}
    		
    				
    		objGame.lastRotation = numRotation;
    		
    		objGame.lastX = _root._xmouse;
    		objGame.lastY = _root._ymouse;
    	}
    	
    };
    Anyone offer any advice to improve this as it doesnt really work?
    Paul Steven
    http://www.mediakitchen.co.uk

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    Hmmm, what's wrong with it? It seems alright for me.
    New sig soon

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    501
    It seems a bit erratic. What I would like is for the plane to rotate smoothly either clockwise or anti-clockwise based on the movement of the mouse - not based on the angle of the cursor to the plane position.

    I have attached file

    Thanks

    Paul
    Attached Files Attached Files
    Paul Steven
    http://www.mediakitchen.co.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center