Point At Mouse
hey, i need the help of some of u trigonomitry people out there ) ive created a black box with the dimensions 100 *5 and made it into a movie clip with the center in the right corner and with this AS i was hoping to make it always point at the mouse
Code: onClipEvent (enterFrame) { xd=_root._xmouse-this._x; yd=_root._ymouse-this._y; this._rotation=100*Math.tan(xd/yd)*-1; trace("rotation "+this._rotation); trace("x_dist "+xd); trace("y_dist "+yd); } now this , is not working and i want to know how i would make it work so one of the short ends of the box is always pointing in the direction of the mouse.
Thanks VOS
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 01-19-2005, 10:48 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting An Object To Point Towards Mouse - Rotation - Mouse Follower
Hi guys, I'm kinda getting lost in AS3 and was hoping if someone here can help out.
Picture an arrow in the middle hanging from the top and at the bottom two buttons, Left and Right. When the user enters the frame with mouse, I want the arrow to point towards the mouse maybe with some ease if necessary. Obviously the user will either choose Left or Right so it will look like the arrow is pointing to the button. But I want the arrow object to follow the mouse in realtime and thats why i want to get it to follow the mouse and rotate accordingy, rather than making an animation such as play this when mouse is on button Left (OnRollOver).
So I'm looking for a good script to do that . Any help is appreciated.
TRIG - MC Follow Mouse Rotate Around Mouse Point
I have read and i think i 'fully' understand (unless it gets more complicated or what not) the trig tutorial, on this site.
no offence i cant remeber who's tut.
i can make a movieclip circle another movie clip,static or moving.
but now, i have a movie clip that follows the mouse pointer when the up key is toggled.
and i want this movieclip to rotate around the mouse point,when the left key is either pressed or toggled, and reverse this movement for the right key.
i have tried a few things for this i can not get it to rotate, it just seems to jitter randomly.
i have tried rotating a completely static MC around mose point which also failed..
any help thanks?
this is the code that makes the clip face the mouse, and move to its position.
its a function called from another function.
its followed from a tut but i do understand it. This is not what im having troublewith,this works.
Code:
myRadians = Math.atan2(_root._ymouse-MYCLIP._y, _root._xmouse-MYCLIP._x);
myDegrees = Math.round((myRadians*180/Math.PI))+90;
MYCLIP._rotation = myDegrees;
_root.yMove = Math.round(_root.yChange/20);
_root.xMove = Math.round(_root.xChange/20);
MYCLIP._y += _root.yMove;
MYCLIP._x += _root.xMove;
_root.yChange = Math.round(_root._ymouse-MYCLIP._y);
_root.xChange = Math.round(_root._xmouse-MYCLIP._x);
}
to make it clear what i want, a MC that will circle the mouse point, when key is down or toggled, this movieclip also needs to be capable of moving towards mouse point on key down or toggle.
Cheers.
Mouse Point At Target/follow Point "challenge"
hiya.
I ve got a self made cursor to use on my flash site. Ihave mad it follow the mouse and Ive used code to hide the mouse. so at the momment it looks like a custom cursor. great!
What I want to happed is to have this new cursor (arrow) always point at a certain point on the screen (say for now the center) so say the cursor was on the left of the screen it would point right (to the center.)
Im guess this would be fairly simple but I just cant get my hea round it.
Any helpers???
I would have thought it would be simillar to the script which has and object fix in a postion but always point to the mouse location.
Point At Mouse
What script would i put in a mc if i wanted it to point at the mouse (if it's always in the middle of the screen).
Reply please, i will be greatly thankful.
Btw i am using mx pro 2004
Point At Mouse
hey, i need the help of some of u trigonomitry people out there )
ive created a black box with the dimensions 100 *5 and made it into a movie clip with the center in the right corner
and with this AS i was hoping to make it always point at the mouse
Code:
onClipEvent (enterFrame) {
xd=_root._xmouse-this._x;
yd=_root._ymouse-this._y;
this._rotation=100*Math.tan(xd/yd)*-1;
trace("rotation "+this._rotation);
trace("x_dist "+xd);
trace("y_dist "+yd);
}
now this , is not working
and i want to know how i would make it work so one of the short ends of the box is always pointing in the direction of the mouse.
Thanks
VOS
2D Map With Marked Point When Mouse Over ?
Hi!
Looking for a simple 2D map. I need to specify some spots on it,
when the mouse is over the point, it changes color and shows some description.
Additional functionality - like linikng the points would be awesome.
If you could provide me with any link, or send me a template, I could use - that would be greet.
Thanx for going through it.
2D map - points with a description on it
How Can I Get A Cannon To Point Towards The Mouse?
im sorry if this question(or a similar one) has already been asked, but i've looked around and found nothing.
so, what i want to do is make my cannon rotate around so that it is pointing towards the mouse, without actually moving towards the mouse.How can i do it?
it'd be gr8 if i could get some help, im new to www.actionscript.org
Follow Mouse At A Point
Go to http://www.flashgames247.com/play/599.html and play the first assignment for an example. On this game when you move the mouse the gun points towards the mouse and hence rotates. Can somebody explain how to do this simply (an example in an .fla would be useful), I'm not very experienced with actionscript so please explain in detail. Thanks for posting. Fanderson2
Mouse Point Effect
hi friends,
i visited one of the best flash designer website "wactory.com" they designer brookeburke's web page, i just like to know, they are used some script in their website, when we move our mouse point, appear lines on background, anyone know this script?
Eyes That Point To Mouse
Hi guys, i've trying this for two days, without any result.
What i want is that the eyes of a face always point to mouse.
I hace calculated what should be the angle. Imagine ma mc is the movieclip where there is an eye drawn.
this is my as:
mc._rotation=Math.atan(abs(mc._xmouse-mc._x)/abs(mc._ymouse-mc.y))*360/(2*Math.PI);
I try it, but the eyes do nothing, does anyone has or know where i an get any example that could help me to realise where ir the problem.
Thanks a lot
Object Point At Mouse?
Hello, I'm tring to design a basic proof-of-cocept game in Flash, and I can't seem to get this working properly: I need a movie clip able to orient itself to be pointing at the mouse even as the clip moves around the screen. What I'm attempting is something heli-attack like in that it will be a platform-based shooter, but there's a few things I have planned... Anyways, if aybody could help me out, I'd really appreciate it!
Help: Point To Mouse & Rotate Only If In Movieclip
I'm using Flash 5.
What I want my movie to do:
I have a color wheel movie clip with a pointer arm movie clip in the center. If the mouse if over wheelMC then the pointer should rotate to follow the mouse. If the mouse is outside wheelMC then the pointer does nothing.
What it actually does:
The pointer rotates & points to the mouse where ever it is.
My code is on the pointer movie clip:
onClipEvent (enterFrame) {
if (_root.wheel.hitTest(_root._xmouse, _root._ymouse, true)) {
a = pointer._y-_ymouse;
b = pointer._x-_xmouse;
angleA = Math.atan2(a, b);
degrees = angleA/(Math.pi/180);
setProperty ("pointer", _rotation, degrees);
}
}
[F8]Changing The Mouse Reference Point?
This could actually solve the problem i have from my other post.
When i load my external swf(its a game that uses the mouse co-ordinates to use startDrag and calculate a hit test), the game uses the coordinates based on the entire main flash file which is much larger. If i position the movieClip at (0,0) then all is fine.
My question is: If i wanted to move the movieclip somewhere other than (0,0), is there any way (without editing the game file) to change the mouse x and y values when being read by the game? Like maybe a onRollOver function?
Thanks before hand
[F8] How To Set Point Of Origin For Object That Follows Mouse
Hi, I have the following problem: I've set up a file in which an object follows the motion of the mouse, but when the file loads, the object starts as a default in the top left corner rather than where I placed it. How can I get the object to start from a designated location in the file? Everything I've tried so far doesn't seem to work...
Here's what I have right now:
A layer with an Object (set up as movie clip)
A layer with the following actionscript:
Code:
object.onEnterFrame = function() {
var xMouse = _root._xmouse;
var yMouse = _root._ymouse;
this._x = xMouse;
this._y = yMouse;
}
In addition, I would like the object to return to that same default location when the mouse is moved off of the file area.
Anyone who could provide guidance would be greatly appreciated!
Thanks a bunch.
Until then, Mr. T will be sitting here pitying me...
Movie Clips That Point Towards The Mouse
hi i am looking to be able to have a movie clip that always faces the direction of the mouse and don't have the first clue how to do it. all i can guess is that it uses radians in some way. please can you help me?
cheers
Making Image Point To Mouse
I have a pointer on the screen that I want to stay in a fixed location. I do want it to point to where the mouse is at on the screen though. Has anyone ever done this?
Follow The Mouse From A Fixed Point
Hi - I am trying to make a character in Flash move his arm as you move the mouse across the file. In other words I want to have one point of an image fixed in place (his shoulder) but the other end moving to where the mouse is (preferably with a second joint as his elbow). Does anyone know of any tutorials I could use?
Thanks for any help you can give!
Object Rotates To Alway Point At Mouse
I am in need of a piece of code that will cause my arrow movieclip to point in the dirrection of the mouse, am new to action script, any help greatly appreciated.
Rotate With Ease To A Point Using X, Y Mouse Coordinates
I'm a bit of a beginner when it comes to programming actionscript so here is what I've run into. I've made a makeshift compass and when you roll over the compass I want the needle to follow the mouse cursor, while at the same time there is another mechanism attached that twists to the category depending on mouse position. This much I have programmed into the movieclips. Now what I need to add to the code is the bit that makes the compass needle ease back to whatever category you are at once the mouse leaves the circle (the compass). I would assume that you would set everything up on a mouse coordinate system and then reset the rotation of the needle once the mouse leaves the circle, but I just don't have the know-how to figure it out. I would appreciate ANY help as I've been browsing through the forums trying to find something of help but to no avail. Thanks guys!
How To Point To A Specific Scene When Mouse Is Inactive?
Hi all.
I'm working on a presentation to be presented on a Trade Show. It have an inicial movie, running in loop, but with a Menu bar, so people could stop the movie and go to a product catalogue.
I want that when people stop looking the catalogue and go away, the presentation go (after a few minutes) to the initial movie loop again.
How can I do this?
Thank's for your attention.
Need Simple Script To Get Angle From Point To Mouse
I am a little rusty on my trig. I need a script that gets the angle from a point to another point.
I am using this script, but it doesn't quite work in certain positions.
function aimPlayer() {
aimDifx = engine.crosshair._x-engine.player._x;
aimDify = engine.crosshair._y-engine.player._y;
aimDifxy = Math.sqrt((aimDifx*aimDifx)+(aimDify*aimDify));
if (aimDifx>=0) {
aimAngle = Math.tan(aimDify/aimDifxy)*(18*Math.PI);
} else {
aimAngle = -(Math.tan(aimDify/aimDifxy)*(18*Math.PI))+180;
}
engine.player.gun._rotation = aimAngle;
}
[CS3] Scale A Beam To Mouse Co-ordinates/point?
I have attempted to make a movieclip scale in the y axis using _yscale but I can't seem to make it scale to the exact mouse co-ordinates.
Its within a rotating movie clip (controlled by the position of the mouse) and that works fine.
Here's the code I'm using at the moment. I know the math is wrong, but I can't really figure out where:
Code:
onClipEvent(enterFrame){
var disty = this._y - this._ymouse
var dist = Math.sqrt(disty*disty)
this._xscale = 100 + dist;
}
Any ideas would be greatly appreciated.
How To Point To A Specific Scene When Mouse Is Inactive?
Hi all.
I'm working on a presentation to be presented on a Trade Show. It have an inicial movie, running in loop, but with a Menu bar, so people could stop the movie and go to a product catalogue.
I want that when people stop looking the catalogue and go away, the presentation go (after a few minutes) to the initial movie loop again.
How can I do this?
Thank's for your attention.
AS2 Scale A Beam To Mouse Co-ordinates/point?
I have attempted to make a movieclip scale in the y axis using _yscale but I can't seem to make it scale to the exact mouse co-ordinates.
Its within a rotating movie clip (controlled by the position of the mouse) and that works fine.
Here's the code I'm using at the moment. I know the math is wrong, but I can't really figure out where:
Code:
onClipEvent(enterFrame){
var disty = this._y - this._ymouse
var dist = Math.sqrt(disty*disty)
this._xscale = 100 + dist;
}
Any ideas would be greatly appreciated.
How To Point To A Specific Scene When Mouse Is Inactive?
Hi all.
I'm working on a presentation to be presented on a Trade Show. It have an inicial movie, running in loop, but with a Menu bar, so people could stop the movie and go to a product catalogue.
I want that when people stop looking the catalogue and go away, the presentation go (after a few minutes) to the initial movie loop again.
How can I do this?
Thank's for your attention.
Can Someone Point Me Toward Some Tutorials On Scrolling Images On Mouse Movement?
hi,
im fairly new to flash, and am trying to create a picture gallery. i got the images scrolling smoothly using button rollOver, but would like the gallery to work on mouse movement. like this
http://www.yugop.com/ver2 the menu system on this site is what im trying to achieve, but not in such a complex form. all i want to do is get images scrolling from left to right on the mousex movemnet. when the mouse is in the middle i want the scrolling to stop. the further the mouse moves from the center the faster the images scroll (depending on mouse direction), untill they stop scrolling at the last image. i want this scrolling to happen in set area, once the mouse is outside this area i want the mouse to behave as normal.
any direction towards tutorials that could help me learn would be greatly appreciated
thanks
yashombi
>>relative Distance Of Mouse To A Point And Flash Animation<< Plz Help
hi all,
im trying to figure out how to write a script that would make it possible to play back and forth though a flash movie controlled by the users' mouse position relative to the center (or any specified point) of the scene. say for example, if the mouse is far from the center it plays the first frame, then as the mouse moves closer to the center, it plays further into the movie. the is this possible?? is there any information out there on this? thanx
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
Mouse Reference Point Change In Firefox When Scrolling
I'm having major problems with my flash site in firefox. If I scroll let's say, 50 pixels, the reference point gets all screwed up so when I'm going to click on something I have to click 50 pixels below the buttons to hit them.
I don't know if the problem can be that I'm importing external swfs? Or the combination with this and my preloader?
Anyone has a clue what to do?
Function That Return Mouse Direction As Cardinal Point
Hi all, i'm searching for a function that return the mouse movement as Cardinal Point.
In other words i would like to have as returned value, if mouse is going from down to top, North, if mouse move from left to right, should return East ... and so on ...
i think is not easy to code, anyway i can't with my capabilities. Can anyone help in this or give some input to solve?
Help With Math.atan2(); Rotating Movieclip To Point At Mouse
I am trying to make a line point to wherever the cursor is when i stumbled upon the Math.atan2(); function. It appeared that i would put line.rotation = Math.atan2(1,1); to get 45 degrees or pi/4, but i was wrong. It barely moved the movieclip at all.
So what i'm trying to do is to get this movie clip to rotate along with the mouse so the line is always pointing at the cursor.
Also, how would you get movieclip to move along the line created by the line of these two points?
Thanks in advance!
Dragable Mouse Pointer Point Toward An Invisible Movie Clip?
Hi, I want to have a dragable movie clip point (which replaces the cursor) at an invisible movie clip. The pointer is a finger and its function is to give the user a visual cue to click in an area to get information.
I found a post about having a movie clip follow the mouse using this:
Code:
this._rotation = Math.atan2(dy, dx)*180/Math.PI;
What would I use to achieve the opposite - have the dragable clip point at something on the stage?
How To Control A Movie Clip's Motion With Keys While Having It Point At The Mouse?
I'm scripting a top-down game here, and it's pretty much my first major Flash project and I'm sort of stuck. My AS appears to be all sound, so I can't figure out why this doesn't work.
Below is the code that is on my player character.
ActionScript Code:
// The 'onClipEvent' header is to make sure everything is executed on each frame so that the game always works
onClipEvent(enterFrame){
// Pointing script for the object
this.pointAt(this._parent._xmouse, this._parent._ymouse);
// Movement keys
if (Key.isDown( 65 )) {
this._x = this._x - movement;
}
if (Key.isDown( 87 )) {
this._y = this._y + movement;
}
if (Key.isDown( 83 )) {
this._y = this._y - movement;
}
if (Key.isDown( 68 )) {
this._x = this._y + movement;
}
// End movement keys
}
This is the code that defines variables and makes the pointAt script possible, or maybe it's unnecessary...
ActionScript Code:
// Point at cursor script
MovieClip.prototype.pointAt = function(x,y)
{
var dx = x - this._x; // distance to other object on x-axis
var dy = y - this._y; // distance on y-axis
var dist = Math.sqrt(dx*dx + dy*dy); // true distance (using Pythagorean theorem)
var angle;
// figure out angle in radians (0- 2*PI)
if (dy <0)
angle = Math.PI*2-Math.acos(dx/dist);
else
angle = Math.acos(dx/dist);
// convert to rotation value (angle in degrees or 0-360)
this._rotation = angle*180/Math.PI;
}
// End point at cursor script
//----------------------------------------------------------------------------------------------
// Variables
// Player Variables
movement=1
// Enviromental Variables (Wind, Gravity, Drag, etc.)
FrisbeeSpeed=8
gravity=0.7
drag=0.8
wind=0.4
And of course, the code for my crosshair
ActionScript Code:
onClipEvent (enterFrame) {
this._x = _root._xmouse;
this._y = _root._ymouse;
Mouse.hide();
}
As you can see, I tend to document my code pretty well so others can use it if they need to. But what my problem is is that when I press D - No other key, just D - my player movie clip teleports to the center of the movie and won't move. My other controls don't work either. Is there something missing here? Or is my coding just wrong? Please help!
Draw A Line From Any Point A To Any Point B Dynamically Through Actionscript
I am trying to make a file where there are several locations made on a map. If a person clicks on one location A and then another location B, there is a plane that flies from A to B and there are 2 text fields that get populated with the names of A and B destinations. This animation is scripted. I wanted to animate a dotted line from point A (from destination of the plane) to point B(to destination of the plane) through action script too so that there is a dotted line following the plane animation.
Thanks
Aneesha
[CS3] Find Highest Point And Farthest Point Of A Parabola
Hi Guys, I've been using for forum extensively over the past few weeks and have found almost everything I needed until now...
I'm moving a ball using something similar to the following code:
Code:
var spx:Number = 3;
var spy:Number = 7;
var g:Number = 0.1;
var bmove:Boolean = true;
onEnterFrame = function() {
if (bmove) {
move_ball();
}
stop_ball();
}
function stop_ball() {
if (ball._y > 350) {
bmove = false;
}
}
function move_ball() {
spy = spy-g;
ball._x += spx;
ball._y -= spy-g;
}
Is there a way to find the maximum height and farthest point of the parabola it describes? I want to display a path guide using curveTo which shows the route of the ball.
Thanks.
Moving Object From Point A To Point B - Mathematical Problem
Hi,
I have mathematical problem.
I want to move object from point A to point B but not just X or Y aixis. For example point A(0,0) and point B(500,500).
Please if somebody can send me generic equation to put in ON_ENTER_FRAME event so on each frame object is a little bit closer to point B.
Thanks,
Find Highest Point And Farthest Point Of A Parabola
Hi Guys, I've been using for forum extensively over the past few weeks and have found almost everything I needed until now...
I'm moving a ball using something similar to the following code:
Code:
var spx:Number = 3;
var spy:Number = 7;
var g:Number = 0.1;
var bmove:Boolean = true;
onEnterFrame = function() {
if (bmove) {
move_ball();
}
stop_ball();
}
function stop_ball() {
if (ball._y > 350) {
bmove = false;
}
}
function move_ball() {
spy = spy-g;
ball._x += spx;
ball._y -= spy-g;
}
Is there a way to find the maximum height and farthest point of the parabola it describes? I want to display a path guide using curveTo which shows the route of the ball.
Thanks.
Drawing Line Dynamically From Point To Point
Here is what I am looking to do, I will try and be specific:
I would like to create an MC:
when loaded, draws a line dynamically from the first x/y point released on the stage to the next x/y point released, then from there to the next x/y point released, and so on. Creating a path from point to point, wherever you release. Tracing the path of the user (based on onRelease points).
This could be a closed set, where, for example, I would have 10 MC's on the stage that are all potential points for the line. The catch is that I want the user to define the order, selecting the MC's in any order and having a line drawn that traces the users selections.
Or it could allow the user to release anywhere within the parent MC.
I am moderately familiar with drawing a line dynamically, but don't know how to write what I am looking for.
Any help??
Thanks so much.
How To I Move From Point To Point And Leave A Trail
What i'm doing is have a word appear and then a line come from it and move to a point, while the line is moving what i want it to leave a trail behind it as if someone was drawing the line from 1 point to another, I hope i have explained it ok,
If anyone knows how to do this can you let me know.
thank's
Move An Object From One Point To Another Point On Graph
Basically what I like to ask is how to move a object from one point to another point based on the point tat you have clicked on a graph. For example, If I click on this coordinate (2,3) on graph, the object (movie clip) will move to that point.
Registration Point Vs. Transformation Point
I'm extremely frustrated with the behavior of Flash MX 2004's registration/transformation points. I just learned that the distinction between the two just happened with the release of Flash MX 2004. I'd like to know how in the world I'm supposed to transform a symbol relative to its corner or side, seeing how the transformation point insists on being in the center of the symbol every time.
Let's say I have a 200x200 square shape. If I want the transformation point to be in the lower left corner, it looks like I have to:
1. Put the registration point in the center when I create the symbol
2. Double click on the symbol
3. Move the shape 100 px to the right
4. Move the shape -100 px up
5. Exit out of symbol editing mode
which is five times more complicated a process than if they had kept the behavior like it was. Or at the very least, change the Symbol Creation dialog box to this:
Or am I missing something?
Move An Object From One Point To Another Point
Basically what I like to ask is how to move a object from one point to another point based on the point tat you have clicked on a graph. For example, If I click on this coordinate (2,3) on graph, the object (movie clip) will move to that point.
Laser From Point X Go To To Point Z. Sort Of
ok i need help! here is what i have so far, this code that i show u is on the laser movie clip (it has been duplicated allready and this is just the code that is on it:
Code:
onClipEvent (load) {
this._x = _root.mech._x;
this._y = _root.mech._y;
laserMoveSpeed = 10;
this.targetAngle = Math.atan2(aim._y-mech._y, aim._x-mech._x);
this._rotation = this.targetAngle/(Math.PI/180);
}
onClipEvent (enterFrame) {
//here is code that will move laser in direction of where
//the mc instance named: aim was when clicked
this._x += Math.cos(this.targetAngle)*this.laserMoveSpeed;
this._y += Math.sin(this.targetAngle)*this.laserMoveSpeed;
}
mech is the instance name for the point the laser shot will start at, aim is the mouse mc whhere you click and then it duplicates the mc, and then this code should get run , the only thing that works is when u click, one of the laser mc shows up, so u can keep clicking and u will get tons of lasers on the screen, but they dont move and just stay at the point where the mech was when shot. how come this code isnt making the laser move in the right direction, so why dont it move?
EDIT: on the onload part i just added a trace(targetAngle); it displays the output of NaN. what does that mean>?
Add Point And Deduce Point In Flash
Hello everyone,
I am a beginner in Flash and currently I am doing my final year project on a website development. I plan to create a happening website by providing members to actually collect points while they perform some activities like membership sign up will earn them 500 points, submit photo will earn them 100 points and so on.
They can collect point under they membership account and use the point to redeem some stuff. As they redeem their point in their account will automatically deduced accordingly. So the problem here is I am unable to figure out what actionscript is this called- able to add points and deduce point according to the activities the member do in the website. I would be really grateful if you guys can help. Really really need help. I have no idea where to start off. Thank you in advance.
cheers
|