00:00
00:00
Newgrounds Background Image Theme

PalmMan just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: move to clicked position

1,211 Views | 13 Replies
New Topic Respond to this Topic

AS: move to clicked position 2006-02-02 14:59:59


AS: main

*note* any lines of code with // or /* at the beggining are just comments and do not affect the code, you can deleate these lines if you wish.

this is just a really easy way to make somthing move to the mouse when you click, right, so first make a movie clip (just a circle will do for now) this will be the main character, and add these actions (f9)

onClipEvent(enterFrame){
/* does the following actions at your movies framerate per second*/
if(this._x>_root.point._x){
_x-=5}
/* if_x posision of this MC is greater than the_x position of point,move left*/
if(this._x<_root.point._x){
_x+=5}
// same principles for the rest of the code
if(this._y>_root.point._y){
_y-=5}
if(this._y<_root.point._y){
_y+=5}}

now your wondering what point is, well its the point that the MC goes to when you click so create another movie clip (a smaller circle) give it the instace name of point and give it these actions

onClipEvent(mouseDown){
// everytime the mouse is pressed do the following actions
this._x=_root._xmouse;
// goto the x poision of the mouse
this._y=_root._ymouse}
// goto the y position of the mouse

now test your movie i dare you XD . you should have somthing like
this

Response to AS: move to clicked position 2006-02-02 15:06:16


yu should have use trig functions. im sorry i just dont like how he only moves in angles of 45 degrees

Response to AS: move to clicked position 2006-02-02 15:07:26


At 2/2/06 03:06 PM, FlaccidLad wrote: yu should have use trig functions. im sorry i just dont like how he only moves in angles of 45 degrees

yeah, but i was just trying to make it easy for begginers

Response to AS: move to clicked position 2006-02-02 15:09:50


can u show an example of what it does?

Response to AS: move to clicked position 2006-02-02 15:10:31


At 2/2/06 03:09 PM, -fenix- wrote: can u show an example of what it does?

he did, check the bottom of the tut

Response to AS: move to clicked position 2006-02-02 15:21:11


if you want the character to "face" the way hes walking add this code to the movie clip

onClipEvent(enterFrame) {
_rotation=Math.atan2(_y-_root.point._y,_x-
_root.point._x)*57.3;
}

Response to AS: move to clicked position 2006-02-02 15:25:08


onClipEvent(enterFrame) {
_rotation=Math.atan2(_y-_root.point._y,_x-
_root.point._x)*57.3;
}

no no no no no
_rotation=180*Math.atan2(_root.point._y-th
is._y,_root.point._x-this._x)/Math.PI


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: move to clicked position 2006-02-02 15:31:29


probly same thing

Response to AS: move to clicked position 2006-02-02 15:34:05


At 2/2/06 03:31 PM, FlaccidLad wrote: probly same thing

he just converted it from radians to degrees and it does so the same thing.

Response to AS: move to clicked position 2006-02-02 15:35:12


firstly... a AS topic has to teach you the code not just post it and go YAY code! thats foss main..

and secondly
its a crap script anyway

Response to AS: move to clicked position 2006-02-02 15:37:59


At 2/2/06 03:35 PM, shazwoogle wrote: firstly... a AS topic has to teach you the code not just post it and go YAY code! thats foss main..

i did explain the code

and secondly
its a crap script anyway

make a better one then and shame me ^^

Response to AS: move to clicked position 2006-02-02 15:43:29


At 2/2/06 03:40 PM, Khao wrote:
At 2/2/06 03:37 PM, -reelbigcheese- wrote:
make a better one then and shame me ^^
nearly everybody who has a topic in AS: Main made a better one...

lol, i wish everyone would stop trying to argue with me , i could have made it better with trig and stuff, but i was aiming this at beggingers so i tried to make it as simple as possible.

Response to AS: move to clicked position 2006-02-02 15:45:05


if you can make a better one then do it now.


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: move to clicked position 2006-02-02 15:57:17


var px:Number;
var py:Number;
var ang:Number;
var dist:Number;
var dx:Number;
var dy:Number;
var walk:Boolean = false;
var walkSpeed:Number = 10;
var walkMc:MovieClip = myMovieClip;
onMouseDown = function () {
px = _xmouse, py = _ymouse;
ang = Math.atan2 (px - walkMc._x, py - walkMc._y);
};
onEnterFrame = function () {
if (walk) {
dx = px - walkMc._x, dy = py - walkMc._y;
dist = Math.sqrt (dx * dx + dy * dy);
if (!dist) {
walk = false;
} else {
walkMc._x += Math.cos (ang) * Math.min (walkSpeed, dist);
walkMc._y += Math.sin (ang) * Math.min (walkSpeed, dist);
}
}
};

Untested because Flash, and several other programs, refuse to open for some damn reason. It's driving me crazy, I've looked all over the internet for an explanation / solution, but I just can't find one.


BBS Signature