|
|
|
#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:
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;
}
}
Last edited by MichealStar; 09-02-2009 at 03:20 AM. Reason: [RESOLVED] |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|