To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Math and Physics

Reply
 
Thread Tools Search this Thread Display Modes
Old 09-02-2009, 01:32 AM   #1
MichealStar
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
File Type: fla angle_test.fla (32.0 KB, 17 views)

Last edited by MichealStar; 09-02-2009 at 03:20 AM. Reason: [RESOLVED]
MichealStar is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Math and Physics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:19 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.