-
[RESOLVED] moving char with a mouse click. Does not work always ?
Hi
I have this code to move the char when clicking mouse button but it does not always work sometime the char just keeps on moving, any Idea why?
// player follows mouse clicks
if (ASnative(800, 2)(1)){
pressed=1;
angle = Math.atan2(_ymouse - char._y, _xmouse - char._x);
angleorg=angle;
mousexcheck=_xmouse;
mouseycheck=_ymouse;
}
if(pressed==1){
char.vx = charspeed * Math.cos(angleorg);
char.vy = charspeed * Math.sin(angleorg);
char._x += char.vx;
char._y += char.vy;
endcheckx=mousexcheck-char._x;
endchecky=mouseycheck-char._y;
if(endcheckx>=0 and endcheckx<=10 and endchecky>=0 and endchecky<=10){
pressed=0;
}
} // if pressed
-
This is the final code might as well post it si
// Made By Einar Odinn Holm
//######player follows mouse clicks
if (ASnative(800, 2)(1)){
pressed=1;
angle = Math.atan2(_ymouse - char._y, _xmouse - char._x);
mousexcheck=_xmouse;
mouseycheck=_ymouse;
}
if(pressed==1){
char.vx = charspeed * Math.cos(angle);
char.vy = charspeed * Math.sin(angle);
char._x += char.vx;
char._y += char.vy;
endcheckx=mousexcheck-char._x;
endchecky=mouseycheck-char._y;
if(!angle){pressed=0;}
if(endcheckx<10 and endcheckx>=-10 and endchecky<10 and endchecky>=-10){
pressed=0;
}
} // if pressed
-
.
Hi,
Sometimes it helps if you tell us the full code, example, whether you are using onEnterFrame, clipEvent or something else to fuel your char character.
You seem to miss vars out, example charspeed.
Can you tell me why you are using (ASnative(800, 2) instead of simply using Key.isDown(1)
-
Hi
its in A onEnterframe and there is one var needed charspeed
there is no special reason that i know off why im using Asnative
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
|