A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Calculate Simple Angle

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    5

    Calculate Simple Angle

    [RESOLVED]
    I've finally got it to work, just had to subtract the new angle from the moving MC(ball)'s current rotation.

    So this is how it should look after being fixed:
    Code:
    onEnterFrame = function(){
    	if(this.hitTest(_root.ball._x, _root.ball._y, true)){
    		newx = _root.ball._x-_x;
    		newy = _root.ball._y-_y;
    		angle = (360/Math.PI)*(Math.atan2(newy, newx));
    		_root.ball._rotation = angle-_root.ball._rotation;
    		play();
    	}
    }
    -----------------------------------------------------------------------------------------------

    I've been trying to figure this one out for sometime now, I have seen a lot of posts in this forum on getting the right angle after collisions.

    What I'm trying to do is get the rotation(angle) of a moving circle after colliding with another circle. I just want to do this simple and get the angle so that the moving circle just turns at the correct angle. No need to worry about acceleration/speed.

    Here's my code as of now, there are two movie clips(two circles). The moving one is called "ball" and the other one is nameless.

    Code in Movie Clip "ball":
    Code:
    onClipEvent(load){
    	sp = 5;
    }
    onClipEvent(enterFrame){
    	xsp = sp * Math.sin(_rotation*(Math.PI/180));
    	ysp = sp * Math.cos(_rotation*(Math.PI/180));
    	
    	_x += xsp;
    	_y -= ysp;
    }
    Code in the nameless Movie Clip:
    Code:
    onEnterFrame = function(){
    	if(this.hitTest(_root.ball._x, _root.ball._y, true)){
    		newx = _root.ball._x-_x;
    		newy = _root.ball._y-_y;
    		angle = (360/Math.PI)*(Math.atan2(newy, newx));
    		_root.ball._rotation = angle;
    	}
    }
    I know there has been a lot of tutorials and help on this similar topic guys, but I'm having problems with this. Any help is much appreciated.
    Attached Files Attached Files
    Last edited by MichealStar; 09-02-2009 at 02:20 AM. Reason: [RESOLVED]

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