ActionScript 2.0 :: Rotate A Movieclip To Face The Mouse Location
Feb 12, 2005rotate a movieclip to face the mouse location
View 1 Repliesrotate a movieclip to face the mouse location
View 1 RepliesI'm trying to get a MC to rotate to face the mouse using tween:
Code:
import flash.events.MouseEvent;
import fl.transitions.Tween;
stage.addEventListener(MouseEvent.CLICK,clicks);
var tween:Tween;
function clicks(e:MouseEvent):void {
var dx:Number = mouseX-mc.x;
var dy:Number = mouseY-mc.y;
var angle:Number = Math.atan2(dy,dx)*180/Math.PI+90;
tween = new Tween(mc,"rotation",null,mc.rotation,angle,5);
}
While this works fine, there are certain clicks which make the MC pick the longer route to rotate.
I'm making a top down shooter and I'm encountering some interesting code lag with the function I'm using to make the player face the mouse.
Code:
//The function is called through a ENTER_FRAME listener.
//mX & mY are the current position of the mouse.
public function facePoint(mX, mY){
if(this.visible){
this.rotation = (-Math.atan2((this.x - mX),(this.y - mY))) * 180 / Math.PI;
}}
If I hold down two movement keys and then spin the mouse around the character really fast, it builds up some kind of buffer that sends the character out of control for a few seconds, even after you've released the keys. Just discovered that reducing the quality to low removes the issue entirely... so its a graphics problem. How to avoid this?
I made a game in AS2 where the player rotates towards the mouse, then discovered you need AS3 for 3D things(which I plan to add later) so I re-made the game in AS3. I think I can more or less do the rest of it but the rotation is driving me crazy. This code works fine in AS2 but when I try it in AS3 it completely fails. The player just wobbles about a 90 degree radius.
[Code]....
I have attached my fla. I want rotate the mc by Mouse drag. But its get some of the jerk.
View 1 RepliesI am looking for direction to this old UFC effect - [URL] that appears on the main page. It is movieclips rotating on different axis based on the mouse position. So far I have found this script:
stage.addEventListener(MouseEvent.MOUSE_MOVE,EnterFrame);
function EnterFrame(e:Event)
{
mc.rotation = (180*Math.atan2(mouseY-mc.y,mouseX-mc.x))/Math.PI + 90;
}
But this only rotates on x and y. What's a way to approach this effect?
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...
I am trying to make an object tween from its starting location to the location of a mouse click. I have a script, but it has a very annoying ease to it.I would LIKE the object to mantain a certain speed during while traveling from its starting location to the mouse click location.
View 16 RepliesHow would I go about doing this but not directly like 360. like lets say my mouse is to the left of the character the character would than face its left frame I made for him like lets say his left frame is frame 2.
View 8 RepliesI have my as2 code for my game im making so far the char can jump and move left and right. make him face the mouse like lets say my mouse is to the x- of my character than I would want his left facing movie clip (which I havent made yet) to be facing that way etc. where I could start heres what I have:
Actionscript Code:
onClipEvent (load) {var ground:MovieClip = _root.ground;var grav:Number = 0;var gravity:Number = 2;var speed:Number = 7;var maxJump:Number = -12;var touchingGround:Boolean = false;}onClipEvent (enterFrame) {_y += grav;grav +=
[Code].....
That's the movement code that lets me move left and right and jump with gravity
I have found scripts to make them face the mouse, but when I try to tweak them to face another movieclip, they don't work.
For examples purpose make the MC: arrow face the MC: target.
Working on a maze game. When the leftkey is pressed the movieclip (char) should turn 90 degrees to the left.
char.scaleX *= -1;
However, the most important thing is that the character doesnt go through the walls of the maze.And I think thats my problem for implementing the code above.Because it doesnt work properly when i put in here;
if(!mazehit) {
char.y += speed;
char.scaleX *= -1;[code].....
I have a problem with the rotating cube tutorial (link below):
[URL]
I'm trying to give an action to each face of the cube. I would like to make it a menu with 6 buttons (one per face)I want to launch a movieclip each time i press a face.
I'm trying to make a dummy from a circular menu that reacts (rotate) to mouse movement, I uploaded a fla example, different colors, size, etc, but essentially the same in
function; but for now I'm freezed how to do somethings, I'm not a programer or actionscripter, but I want to learn.Currently using CS3 and AS2, downloading the FLA example may help.
Ok, in the "fla", you will see a circle who rotates versus mouse movement (I would like to make a delay rotation for a smooth feelling when mouse is moving, those like "_x += (_xmouse/5)" but with rotation. Other thing I would like to do,is... that the movement stops progressively a few degrees before the mouse reach de cian angles(a1,a2), and then, the circles doesn't move if the mouse is moving under those angles, like a... an inactive area(U1), and if it could work with instances.
I am wondering how I can make a top viewed char, that is rotating after my mouse. With an enter frame function or something?
View 1 RepliesI am having problems finding a way to rotate an object with mouse movement when the mouse is down, and stop the rotation when the mouse is released.
I can do drag and drop ok but this doesn't help at all.
our group want to develop a 3D FPS game on flash 11, but how could we make same user experience as Conter-Strike or those classic FPS games without set mouse cursor location?as I know, both ShockWave and Unity Web Player can lock or set location of mouse cursor.we may considering some sercurity issues of open this API, but we are talking about things that desktop apps can do and web apps can not do.
View 7 Replieshow to make a movieclip move base on mouse location similar to the one seen in [URL]. I've found some script that I've been working with and it rotates the Y just fine but keeps rotating. How would I determine a set rotation to stop when I stop mouse movement. Here is my script:
var maxSpeed:uint = 1
box.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
function nLoop(e:Event):void{
[code]....
I'm using the following code to rotate a MC on the Y axis that stops at a certain point. Is there any way to do the same using the tween class so it has a softer finish.
addEventListener(Event.ENTER_FRAME, mcRotation);
function mcRotation(event:Event):void
{
var controller:Number = mouseX - stage.stageWidth * 0.5
[Code].....
I'm trying to achieve the effect found on this site:As you can see, the cursor (the marker) slowly rotates, based on the Y value of the mouse
View 1 RepliesI am horrible at maths and I would like to ask how to make an object ex. an arrow turn into direction of the mouse?ENTER_FRAME and some mathematical functions, but I cant tell which and how to use them.
View 2 Repliesi'm trying to build a "circular" menu that rotate on rollover and mouse move but with no good results. Just something like the yugo sliding menu but with buttons placed around a circonference.I don't need a dinamic menuI need a function that let the menu rotate up when cursor is below the half of the circle and viceversa.I've done a search and found a compass example but i really can't edit it. I'm a newbee and can't really figure out how to rotate a movie clip around its own axes on mouse move..
View 4 Repliesi have made a simple application to move a ball to the location of the mouse. I am trying to adjust my app so that when the ball does move in the same position as my mouse location, it should remove the listener showing that the ball does reach my mouse's destination.
Code:
package
{
/**
* Zenos.as is meant to show how you can demonstrate friction using the Zenos
[Code].....
I am trying to find a menu to implement in the form of a coverflow. I have one accessible but flipping through the covers requires that I click covers, or use the scroll bar.
I am looking for one that will move left and right without requiring clicking. Dragging is probably acceptable. I have been sifting through the google search results, but it seems most coverflows are modeled the same. It doesn't need to be free, but if I could customize it via XML that'd be great.
i have a darkBlueRect rectangle sprite and a copy of the same sprite with a larger scale and a lighter color - lightBlueRect.i'm attempting to shift the location of the lightBlueRect according to the mouse.x location when the mouse is moving over the darkBlueRect. this way if the mouse is on the right of the darkBlueRect than the location of the scaled up lightBlueRect will be on the opposite side and shifted towards the left proportionate to the mouse position and scale. in addition, the lightBlueRect must appear "locked" to the darkBlueRect so lightBlueRect.x must never be more than darkBlueRect.x and lightBlueRect.x + lightBlueRect.width must never be less than darkBlueRect.x + darkBlueRect.width.
[code]...
I have made a simple application to move a ball to the location of the mouse. I am trying to adjust my app so that when the ball does move in the same position as my mouse location, it should remove the listener showing that the ball does reach my mouse's destination.[code]...
View 2 RepliesI have the gun all coded and setup, it's an automatic weapon that fires at the mouse as long as you hold down the trigger, seems simple enough. It updates the target point whenever the user clicks or moves the mouse.My problem though, is that it can't so easily update the target when the user moves their avatar via keyboard keys. As they do this, the target remains at a constant point in worldspace, getting farther and farther from the mouse pointer until they click again or move the mouse. While not a huge issue, this is annoying.A dirty solution I can think of would be updating the target point according to camera movement so that it should follow the mouse even when the mouse isn't moving. This solution seems like a lot of unnecessary work though and I'd like to explore the apparently simpler route first.
View 2 Replieshow to use trig to rotate a movie clip based on (my_mc._x, my_mc._y) and (_root._xmouse, _root._ymouse)?
View 1 RepliesWhat code would I apply to a movie clip to make it rotate on one end according to the angle (location) of the mouse.
View 6 RepliesI am trying to rotate a sphere with the mouse on the x and y axis but the sphere keeps 'roll'ing and flipping it all around.
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[code]....