Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




[mx]; Making A Mc Rotate In Direction Of Cursor



hey all,


what i'm trying to do is make a shooter game,(i know,its been done a thousand times) but what i wanna do is have a player icon standing in the fore ground, and have the arm rotate and move as the cursor moves. essentialy it'll look like the player icon i actually aming.

i've been working with the math function, the SIN, COS and all that good stuff,but to no avail.

i was wondering if any one knows how to link or constrain a MC to the cursor, or Mouse move functions,

any idea is welcome



FlashKit > Flash Help > Flash MX
Posted on: 11-11-2006, 01:52 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Tracking The Direction Of The Cursor To Rotate A Movie Clip
I have a movie where I have a butterfly replacing my cursor. I want to track the direction the user is moving the cursor and rotate the butterfly movie clip to always be pointed in the direction the cursor is moving. I'm kinda new to actionScripting so I can't figure out how to do it. Any help would be appreciated.
jamen
http://www.texasflash.com

How To Detect Direction Of Movieclip And Rotate To Face Direction
Hi!

I have searched this forum, but Im not really sure what to search for, so I havent found anything similar to this. If anyone know, then please post the link to that thread.

I am trying to do some sort of aquarium with random moving amoebas.

But I want the amoebas (movieclips) to detect in what direction (angle) they are moving and rotate so that they "face" the direction they are going in.

I also post the fla file here so anyone can download it to see what I mean.

Thanks in advance

Detect Direction Of Movieclip And Rotate To Face Direction?
Morning all!

Little thing bugging me here.....

I have a movie clip which moves around the stage randomly, but I want it to face the direction it randomly changes to. Can you help or shed some light for me?

Here is my code:


PHP Code:



onClipEvent (load) {
    width = 600;
    height = 450;
    speed = Math.round(Math.random()*2)+1;
    x = Math.random()*width;
    y = Math.random()*height;
    this._x = x;
    this._y = y;
    x_new = Math.random()*width;
    y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
    if (x_new>this._x) {
        sign_x = 1;
    } else {
        sign_x = -1;
    }
    dx = Math.abs(x_new-this._x);
    if ((dx>speed) || (dx<-speed)) {
        this._x += sign_x*speed;
    } else {
        x_new = Math.random()*width;
    }
    if (y_new>this._y) {
        sign_y = 1;
    } else {
        sign_y = -1;
    }
    dy = Math.abs(y_new-this._y);
    if ((dy>speed) || (dy<-speed)) {
        this._y += sign_y*speed;
    } else {
        y_new = Math.random()*height;
    }
}





I have experimented with:

_rotation = (Math.round(180 / Math.PI * Math.atan2(diffy, diffx)) + 360)
and also this._rotation += 1; but not having much luck. Thanks for looking and helping if you can

Cursor Speed And Direction Math To Jump Cursor
Looking for a little help.

I have a project that implements a jump type of desktop mouse interaction. Basically what this does is ...when the user moves the mouse, if moved fast enough (beyond a set speed threshold) the mouse jumps a predetermined amount in the direction the mouse was originally traveling. So I've tried to break it down this way.

First I need to calculate the speed. Based on the below code I can calculate speed on x and y axis but not sure how to evaluate overall speed as a function of both together.


Code:
attachMovie("mouseMC","mouse_mc",1000);
mouse_mc.onLoad = function() {
Mouse.hide();
};

var vxMouse:Number = 0;
var vyMouse:Number = 0;
var xi:Number = _xmouse;
var yi:Number = _ymouse;
mouse_mc.onEnterFrame = function() {
vxMouse = _xmouse - xi;
vyMouse = _ymouse - yi;
xi = _xmouse;
yi = _ymouse;
_root.speedX =vxMouse;
_root.speedY =vyMouse;
_root.cordX =xi;
_root.cordY =yi;
setProperty(this, _x, _root._xmouse);
setProperty(this, _y, _root._ymouse);
updateAfterEvent();
};
I have also added some code to provide a cursor trail.

Code:
onClipEvent (mouseMove) {
if (i >= 100) {
i = 0
}
i++;
this.duplicateMovieClip("flare"+i, i+10);
_root["flare"+i]._x = _root._xmouse;
_root["flare"+i]._y = _root._ymouse;
}
onClipEvent (enterFrame) {
if (this._name == "flareMC") {
_visible = 0;
} else {
this._alpha -= 5;
this._rotation += 2;
this._xscale -= 5;
this._yscale -= 5;
if (this._alpha<=5) {
removeMovieClip(this);
}
}
}
The next part is to evaluate the direction. Now I have done this in reference to a set spot MC using the following code accept that it doesnt update as the mouse moves therefor its only provides the direction from the starting point. Is there a way to update this on the fly as the mouse moves.

Code:
onClipEvent (mouseMove) {
//mouse angle code
x = this._xmouse;
y = this._ymouse*-1;
angle = Math.atan(y/x)/(Math.PI/180);
if (x<0) {
angle += 180;
}
if (x>=0 && y<0) {
angle += 360;
}
_root.angletext = angle;
updateAfterEvent();
}
Thirdly once I have the the speed and the direction how to I go about jumping the mouse distance x in the direction the mouse was moving?

I hope I explained this well enough...if not please shooot me some questions. Any help would be greatly appreciated.

Make Object Rotate The Shorter Direction
I'm creating an object that rotates after I click on a spot. 0 degrees is exactly east and it increases to 180 as I go clockwise so it faces exactly west. If I were to rotate counterclockwise it would change to -1 to -180. I tried working with this setup but when the object is facing 89 degrees and I click -89 (directly above it) it rotates counterclockwise, which is going all around.

PHP Code:



//When I click
xpos = mouseX - player.x;
ypos = mouseY - player.y;
degree = (Math.atan2 (ypos, xpos)) * 180 / Math.PI;

//The enterframe/timer function
if (degree > player.rotation) {
player.rotation += 1;
} else {
player.rotation -=1 ;
}




If there is a method with 0 to 360 degrees please tell me as well.

Rotate Object In Direction Of Drag Movement
I've messed around with getting a draggable object to point to a static object, but I want to have the item I'm dragging actually point in the direction that I'm dragging it in.

Anybody with ideas for how to do this?

Rotate Movieclip According To Mouse Direction, Drag
Hi!

Is it possible to rotate movieclip, while dragging, according to mouse direction and mouse x, y on that clip.

on the picture the 0, 0 of the mc containing red box is where the lines cross, the mouse point is indicated with cursor and around it is the circle where clip's x and y should be constrained and movieclip should rotate according to mouse movement direction for example: when mouse is moving straight down then the clip's x, y rotates up and stops when its 12 o'clock...




Does it make any sense?

Which Turns In The Direction Of Cursor
I'd like to to make a 3d graphic of a cube which rotates in relation to where the cursor is when the user rolls over it.

ie it might rotate clockwise through the y axis by default but when the user rolls over the right side of it, it begins to rotate anticlockwise, in the same way if the cursor is moved back to the left hand side it will rotate clockwise.

any ideas welcome
thanks
j

Change Cursor Depending On Direction
Can anyone lead me in the right direction. I did a search and came up with nothing. I would like the cursor to change depending on the movement of the mouse - moving left or right.

Rotate - Following Cursor Movement
Rotating - follows cursor movement
okay i'm trying to expand this following script so that the circular movement of the objects is clockwise or counterclockwise dependant on the way i move my cursor.



Code:
onClipEvent (load) {
navigation = ["info", "divisies", "agenda", "contact"];
max = navigation.length;
i = 0;
function Circle() {
Radius = 200;
Speed = 1;
for (i=0; i<max; i++) {
_root.attachMovie("Box", "Box"+i, i);
var targ = _root["Box"+i];
targ.attachMovie(navigation[ i ], "mc"+navigation[ i ], 1);
targ.Rotate = i*(360/max);
targ.onEnterFrame = function() {
this.Rotate += Speed;
this._x = 380+(Math.cos(this.Rotate*(Math.PI/180))*Radius);
this._y = 280+(Math.sin(this.Rotate*(Math.PI/180))*Radius);
};
}
}
Circle();
}
4 movieclips from my library are attached to instances of my Box MC and rotate.
Now i know i can control the direction of rotation using


Code:
onClipEvent (enterframe) {
this._x = _xmouse;
this._y = _ymouse;
_rotation = (_rotation+((_root.ymouse-this._y)/speed));
}

well at least i thought i did...what am i doing wrong here?
[Edited by spazmaster on 07-03-2002 at 03:15 PM]

Custom Cursor That Points In The Direction Its Heading?
I've come really close, but the cursor seems to rotate around the mouse location. The code I'm using is below. Can anybody offer some guidance?

Main Time line:

Code:
active = true;

var mcTargetX:Number;
var mcTargetY:Number;

var velX:Number = 0;
var velY:Number = 0;

this.onEnterFrame = function(){

if(active){

mcTargetX = _xmouse;
mcTargetY = _ymouse

velX*=0.7;
velY*=0.7;

differenceX = mcTargetX-cursor_mc._x;
differenceY = mcTargetY-cursor_mc._y;

differenceX*=0.15;
differenceY*=0.15;

velX+=differenceX;
velY+=differenceY;

cursor_mc._x+=velX;
cursor_mc._y+=velY;
}

}

mcTargetX = _xmouse;
mcTargetY = _ymouse;
cursor_mc:

Code:
onClipEvent(enterFrame){

dx = _parent._xmouse-_x;
dy = _parent._ymouse-_y;

angle = Math.atan2(dy, dx);

_rotation = angle * 180/Math.PI;

}
Thanks for any help!

-Dan

**HELP** Rotate Objects With Mouse Cursor
I need some help with my Flash MX project.. We are creating a web page and i have made a custom navigation bar. my site is called High Speed Graphics.. Im using an RPM gauge to select my links. I need someone to help me to get the RPM needle to move with the mouse with i drag around the gauge. The object needs to rotate..not follow the mouse all over the screen like i have found. I need it to look like the needle is selecting the links.. I have already made the links.. i just need to needle to rotate in place with my mouse.. if any can help me please do so.. i would really appreciate it. Its for a college project and i need this asap! please help!! thanks..

How To Rotate An Object With The Mouse Cursor
Hi,

my flash skills are just basic so I´m asking for some help here.

I have to realise a calendar. The hole thing looks like a analogue clock. All days are distributed around a circle. In the middle is the watch hand like pointer. My Problem: The user should be able to rotate the pointer to the current day. I hope this explanation was clear.

How could this be done?

oerdec


edit: I have Flash 5.

Changing Direction Of Cursor Depending On Which Side Of The Screen You're On
Can any body help me? I've been trying for days to find out a way to change the direction of where the cursor points, ie: if you move your cursor to the left, it'll point left, or to the right, it'll point right etc... If anyone can give me any ideas of how i can do this that would be great.

Animation - Random Speed, Direction, Following Mouse Cursor
Hey,

does anyone know how to make a similar animation as this on the top of the page, random speed and direction of bright lights, and when waiting over the button, lights "bombard" it.

http://www.fullyillustrated.com/index.htm

Thanks,
Jure

Getting An Arrow (movieclip) To Rotate And Point At The Mouse Cursor?
Hi all, my first post. Hopefully some helpful folks will help me out

I'm not sure how to script this, and am struggling to find something that demonstrates it to me.
I simply want a movieclip (which will be an arrow) to constantly point at the mouse cursor. So it will be rotating around, as if looking at the cursor as you move it around the screen.

it doesnt actually have to point at the mouse cursor though, it could just point at another movieclip, which the user will drag about.

does anyone have a script lying around that could do this? Or know of a fla somewhere that i can use?

thanks!
Phil

Making A MC Rotate Through AS
How is that done?
I wonder just because, I don't wanna make an animation to rotate a MC.

Making A MC Rotate Through AS
How is that done?
I wonder just because, I don't wanna make an animation to rotate a MC.

Making A Square Rotate With AS
Hi,

I am just testing something out. I have made a square a movie clip and its instance name is square1.

I have made it rotate onRollover with the following script on the frame that it is situated on:


Code:
square1.onRollOver = function(){
square1.onenterFrame = function(){
square1._rotation+=2;
}
}


But I want the square to keep spinning when I click the square, I have used the code


Code:
square1.onRelease = function(){
square1.onEnterFrame = function(){
square1._rotation+=2;
}
}


But this doesn't seem to work,

Any suggestions?

Making A Logo Rotate
Hi, does anyone know of a tween formula to rotate an mc? Not the standard rotation, but a rotation like a globe. It's a simple vector file. An "M" inside an oval.

thanks

Making A Logo Rotate.
Hi all. Please spare me as I am a complete newbie to flash.

I have designed some logos for a website that me and a friend are making.

I want to make one of these logos rotate, but I have no idea where to start in Flash.

Any advice would be greatly appreciated.

Thanks :)

Making Things Rotate
Hi gang,

Just wondering how some developers out there make shapes spin around. I am pretty new to the world of Flash and can't seem to get this working.

Here is an example of what I mean:
http://www.templatemonster.com/flash-te ... 12569.html

When the preloader hits 100% the graphic spins around a couple of times.

Any help with this would be great cause I don't seem to be getting anywhere.

:?

Thanks in advance if anyone can reply.

Help - Making Obj Ease Opposite Direction Of Mouse
Hi. I am trying to make a movieclip (or any object, button, graphic) ease into the opposite direction that my mouse is moving. I have figure out how to do this. I am using the following code applied to the object's action (thanks to some help from a previous post):

onClipEvent (load) {
_x = 0;
_y = 0;
speed = 13;
}
onClipEvent (enterFrame) {
endX = Stage.width-_root._xmouse;
endY = Stage.height-_root._ymouse;
_x = _x +(endX-_x)/speed;
_y = _y +(endY-_y)/speed;
}

My question is however: Look at this following link. You will see how when the mouse is moved the pictures move opposite, but for a limited distance. (they don't go off the screen like they would with the code i posted above). How can I limit the movement of the pictures so it won't go off the screen and only have it move opposite in a limited area? I've tried a lot of manipulation of the code and read many tutorials but cannot figure it out

the link is http://www.templatehelp.com/preset/p...NsHRg3Ag6uS738

I would greatly appreciate any help. Thanks!

Help Please Making Object Rotate With Button...
Does anyone know how to make a button that makes a movie clip rotate X degreese each time I push it.

I've already tried with the SetProberty( "MC", _rotation, "15"); but when you do it this way you can only press the button once then you have to reset the movie again.

One more question....

How do you change the rotation point in ActionScrip. Non-script movies it's just to change it by using the transform tool and you can get a square to spin around its own corner, but how do you do a simular task in ActionScript.

Any help would be appreciated...

Making An Object Rotate, Controllably
Hey, I'm new here, what's going on ...

So I'm trying to make a graphic rotate in Flash MX 2004. I can make it spin by making it rotate CW with the little tool in the properties thing, but I also wanna add some keyframes in the middle of it rotating for alpha changes. If I put a keyframe in it now, I totally screw up the rotation. I'm thinking along the lines of rotating the object at the last frame, then having the first frame tween to it. I've tried that too, but it doesn't tween. I don't even realyl know if this makes any sense ... if you have any questions please ask!

Making _rotate Rotate Smoothly
I have this script:

on (release) {
mc1._rotation -=90;
}

it rotates the movieclip 1, but I want it to rotate smoothly (accelerate and then brake).

How can it be changed?

Rgds

Making An Object Rotate On Its Axis
Does anybody have a tutorial or can help me with making a rotating animation.

Basically I want to make a poker chip rotate on its axis, spinning like a top.

Thanks in advanced.

Noir.

Question About Making An Object Rotate
I have an image of a planet (globe) and was wondering how I would go about making it spin around like a globe does?

Can someone point me to a tutorial for that or explain to me how to do it?

Thanks

[CS3] Making Skew Tween Go In Opposite Direction? URGENT
Hello. I am trying to make a tween where a circle (with writing on it ), tweens so that it "skews" one way, and then back a different way. The problem I am having is Flash won't go the other way. Since this is a TERRIBLE explanation of my problem, I have included a quick, rough example of the problem I am having.

LINK: http://ardesigns.net/example1.swf

See how it tweens the first way fine, but then tweens back the same way, instead of tweening in a circle?! Also, since I will be using this in a video, I can't use AS or AS tweening.

SO, HOW DO I MAKE IT TWEEN IN A CIRCLE?!

PLEASE HELP!!

Thanks in advance,
Sportzguy933

P.S.
My deadline is tonight, or early tomorrow!

Button Making A Movie Rotate Problem?
I have a simple button, and I want it to rotate a movie(pinweel) 45 degrees when pressed.

I tried the action script

on (release) {
setProperty (pinweel, _rotation, 45);
}

But this doesn't work properly. First off it ignores the center point I set, and uses the upper right corner as the rotation point, secondly the button does nothing at all when pressed again.

anybody know whats going on here?
thanks for any help

BG Tile (making A Graphic Repeat/flip/rotate)
Ok,

Here's another attempt... I made a post that makes a MC tile...

here is another challenge, because im trying to keep my flash files sizes to a minimum.

i need to make a repeating background, only im now trying to cut my bg repeating image into 1/4.

so now i have been trying to make a code that will tile the BG image but in this mannor.


XY then -XY
X-Y then -X-Y

and so on, and so on...

XY being the original X and Y scale.... this arrangement will still tile the bg... im just cutting the file size of this image down to 1/4... its what im doing in photoshop anyhoo...


THANKS A MILLION IN ADVANCE,
-manny

Making A Body Part Rotate And Move At The Same Time...
How can you make a body part -- say a arm -- move with the body and rotate at the same time, and with it the elbows rotating, too? Can this be done in with motion tweening?

Making The Cursor Dissapear.
hello
is there any way that for example

from frames 20-25 do not show the cursor on the main screen? or can is set it to invisible for those frames?

i am making an interactive demo. but at one point i just want to have the cursor show something - so that user can't do anything...

i hope you know what i mean
thanks
~chika

Making Mouse Cursor Always On Top?
i have a custom mouse pointer and when i load other movives into the main .swf file it gets put under.
does anyone know the codeing to keep the mouse allways on top?
thanks to anyone who can help!!

Making Custom Cursor
How to make a custom cursor that will be centeret, i mean in the same place with the real cursor.

Making Cursor Disappear
Is there any simple code to make the cursor disappear in a flash program?

I want to do it so that when a variable is set to a certain number, the cursor is not visible.

Making A MC Turn Toward The Cursor
Im quite new to actionscript. I have started doing little games, and I wanted to know how to make a movieclip turn toward the cursor.

Making A MC Act As A Button- Cursor Change
Hi there,

what im really trying to do is manually prompt the default cursor to change to the default hand cursor like it does with ur normal button symbol. Except that I don't want to rely on a button symbol to do this...

Any ideas welcome!!

Thanks,

Lara.

Making The Mouse Cursor Bigger.
Hi,

I'm designing a site for people who are visually impaired and I'm wondering if it's possible to make the mouse cursor bigger so it will be easier to see on the screen. Is this possible??

Making Eyes Follow The Cursor...
I am building a preloader right now and as part of the "entertainment" while waiting, I want to make a pair of cartoon eyes that have pupils that follow the cursor.

Where do I look for this actionscript? How would I do this?

Making It So When You Mouseout, The Cursor Mouses Out Too...
Take a look at this page (It's not done... I'm only working on the banner right now... soon there will be a background and more stuff...)

http://fusionwebdesigns.com/misc/cutup/index/

Mouseover a link, then move the cursor below the link (like out of the movie) and the link stays red. Is there something I can do to fix this?

Making Labels That Follow The Cursor
Hiya,

I'm putting the finishing touches to a little interactive movie I've made that features several buttons. At the moment, a label appears at the bottom of the screen explaining what the button that is being rolled over is, but I'd like to change this, so that a little label appears to the side of the cursor when the button is rolled over. Sort of like when you use a new piece of software and a help label appears when you hover over a button or feature. I've looked at several custom cursor tutorials, but none are quite what I want.

Can anyone offer any help, or point me in the right direction for a tutorial?

Many thanks!

Help Making A Menu That Moves With Cursor
Dear anyone that can help me. I have been struggleing to create a menu that apears and dissappears when the mouse goes near it. An example of what i am trying to create can be seen at:

http://www.zedz.org/

The navigation responds to the cursor position. How is this done?

Many thanks in advance

Matt

Making Eyes Follow The Cursor [FMX]
Hey all... this may seem like a pretty stupid question, so pardon me, but I'm pretty much brand-new to Flash and ActionScript (minus the Tutorials included with it I've taken).

Anyways... I know how to make something follow the cursor (e.g. a ball that moves where your cursor does). However, I'm having a lot of trouble figuring out how to do what I need to for an animation, namely make eyes follow a cursor.

Here's the situation: I need to make a graphic (the eye in the middle of the eyeball) follow the cursor (i.e. look up, look left, look in any number of diagonal directions) depending on where the user moves the cursor. But the eyes, obviously, need to stay put in one static spot and move in a very limited region (the entire white part of the eye, but not beyond it).

Furthermore, the eyes start out staring at the user. How do I additionally make them dart to the edges where they'll be looking around once the cursor is moved?

Does anyone know how I can do this?

Thanks so much for your time!
- andrew kugelstadt

I'm Having Trouble With Making The Random Mouse Cursor
Hi,
I did the Tutorial for making a random mouse cursor but it doesn't work.
what does happen is

A: My mouse cursor still is on top of the alternative mouse-cursor(but i did give the command of hide mouse)

B: One time I almost got it and the cursor was gone but the alternative-cursor was going on and of.

If you know how to solf it please help me.
Thanx already

Making The Mouse Cursor Stay The Same Over A Button
I need to make the mouse pointer stay as normal when it goes over a button.

This must be a piece'o'piss to do, but I couldnt find a tutorial to do it.


Thnx,
Benners.

Making An MC Appear At The Cursor's Location Upon Button Click
Hi people!

I'm constructing a sub-menu that is held within an MC.

This sub-menu is to be activated when a certain area on screen is clicked (through the use of invisible buttons).

This is all ok.

But...What I need to achieve is to have this sub-menu appear at the cursor's location.

Can any body tell me how to do this?

Thank you

Deadhands

Making Cursor Invisible After Idle In 10 Seconds
I have this script that is making the cursor invisible if the mouse have not been moved in 10 seconds.

But it only works correctly the first time. When the 10 seconds is gone the cursor is invisible allright, but after that, the cursor is only visible for 2 seconds at a time each time the mouse has been moved.

The cursor is sort of flicering. What can be done to the script?


var global_nMouseCheck:Number = setInterval(mouseCheck, 10000);
var global_oldMouseX:Number = _xmouse;
var global_oldMouseY:Number = _ymouse;

function mouseCheck():Void {
if (global_oldMouseX+global_oldMouseY == _xmouse+_ymouse) {
Mouse.hide();
} else {
global_oldMouseX = _xmouse;
global_oldMouseY = _ymouse;
}
}
_root.onMouseMove = function() {
Mouse.show();
updateAfterEvent();
};

Making An Object Face My Mouse Cursor
Hey guys.

Basically I have a viewfinder thing mounted on a pole. I have 3 differnt pictures for the head of it. One looking forward, one left and one right.

At the moment I have whipped up some code that determines to some extent where the mouse cursor is and displays the appropraite directional mc.


Code:

mouseListener.onMouseMove = function() {
if (_xmouse <=500) {
if (_ymouse <=380) {
_root.left_mc._alpha = 0
_root.forward_mc._alpha = 100
_root.right_mc._alpha = 0
}
else{
_root.left_mc._alpha = 100
_root.forward_mc._alpha = 0
_root.right_mc._alpha = 0
}
}
else{
if (_ymouse <=380) {
_root.left_mc._alpha = 0
_root.forward_mc._alpha = 100
_root.right_mc._alpha = 0
}
else{
_root.left_mc._alpha = 0
_root.forward_mc._alpha = 0
_root.right_mc._alpha = 100
}

}
};
As you may have noticed already the problem is that it only reacts in terms of square areas. I want the areas to be kinda triangular but I suck at thinking in math terms.

I'll post some images to help explain what i mean.

Thanks
-LetterAfterZ

Copyright © 2005-08 www.BigResource.com, All rights reserved