|
-
Bacon-wrapped closures
Sounds like you might be using degrees instead of radians. If you're using a _rotation property to initialize your angle, it should look like this:
Code:
angle = char.arm._rotation * Math.PI/180;
-
sorry i went on vacation - i hope you're still there.
my character rotation setting things are
Code:
char.onMouseMove = function(){
var __x = _xmouse-this._x;
var __y = _ymouse-this._y;
angle=Math.atan2(__y,__x)*180/Math.PI;
this._rotation = angle + 180;
}
not gonna lie - i have no idea what this is doing :/
ok i get it all... but i dont get the "angle=" line
-
Code:
char.onMouseMove = function(){
var __x = _xmouse-this._x;
var __y = _ymouse-this._y;
angle=Math.atan2(__y,__x)*180/Math.PI;
this._rotation = angle + 180; //what is the "+180" for?
}
I made a few adjustments:
Code:
char.onMouseMove = function(){
var rotX = _parent._xmouse-this._x;
var rotY = _parent._ymouse-this._y;
angle=Math.atan2(rotY,rotX)*180/Math.PI;
this._rotation = angle;
}
My AS2/AS1 is a little rusty. AS3 is better, so I use that:
Code:
function updateAngle() {
var rotX:Number = mouseX-char.x;
var rotY:Number = mouseY-char.y;
var angle:Number=Math.atan2(rotY,rotX)*180/Math.PI;
char.rotation = angle;
}
The code isn't really much different, though, and if I wanted to keep the "this" style code, I would only need to call the target of the event listener. In my code example, however, I didn't bother to make it use a listener. Closer to what you currently have, though, you could put the code inside the char MovieClip, like so:
Code:
function updateAngle() {
var rotX:Number = MovieClip(parent).mouseX-x;
var rotY:Number = MovieClip(parent).mouseY-y;
var angle:Number=Math.atan2(rotY,rotX)*180/Math.PI;
rotation = angle;
}
I never really do that, though, so my syntax might have some small mistakes. I hope I helped. Good luck with your games.
-
i'm sorry... my imcompetance is probably frustating you. first, the "+180" is because the character's starting rotation is 180. so i need that to turn him around. second, i tried the first thing - my code that you changed - and it only worked if i removed "parent.". then i tried the code that you gave me to put in the character itself and that didn't work either.
-
Bacon-wrapped closures
 Originally Posted by adamvan101
sorry i went on vacation - i hope you're still there.
my character rotation setting things are
Code:
char.onMouseMove = function(){
var __x = _xmouse-this._x;
var __y = _ymouse-this._y;
angle=Math.atan2(__y,__x)*180/Math.PI;
this._rotation = angle + 180;
}
not gonna lie - i have no idea what this is doing :/
ok i get it all... but i dont get the "angle=" line
This code already works right? What you need is the bullet initialization code.
I think you're getting confused because I was talking about a variable named 'angle' but there's already one in your code serving a slightly different purpose.
There are two ways to measure angles: degrees and radians. Radians are used by Flash's trig functions; degrees are used by Flash's _rotation property. The conversion factor between them is 2pi/360=pi/180, which is why that ratio keeps showing up.
Let's define 'angle' in radians. Now all your stuff should work.
Code:
char.onMouseMove = function(){
var __x = _xmouse-this._x;
var __y = _ymouse-this._y;
angle=Math.atan2(__y,__x); //now in radians
this._rotation = angle*180/Math.PI + 180; //convert to degrees, turn 180
}
onMouseDown = function() {
b = attachMovie( ... ); //make bullet
b._x = char._x+L*Math.cos(angle);
b._y = char._y+L*Math.sin(angle);
b._rotation = char._rotation; //might add +180 or +/-90
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|