ActionScript 3.0 :: Direct Rotation Between The Object And The Mouse
May 2, 2009
right now I have a code that rotates an object based on the position of it and the mouse. Thats all great but it sucks for a game, It is way too responsive. What I tried doing is making to rotation var:
[Code]...
after that I made rot2 the direct rotation between the object and the mouse: rot2 = Math.atan2(Ydiff, Xdiff) * 180/Math.PI; //(forgive me if this has spelling errors, as I am writing it //by hand right now) then I make rot effect the object: object.rotation = rot; now that the basics are set up I just need to make a code that compares rot2 and rot, if rot is less than rot2 it adds on to rot, if it is greater, then it will subtract.
(source at bottom) this all works well until you hit the most annoying part, the one i cant figure out how to fix.... basically there is a gap where the numbers go from 180 to -180, so the code flips out, reads this as it is supposed to, but this makes the object rotate a full 360 degrees around instead of just like 2 degrees to bridge the gap. If anyone has insight on this or thinks they might know what to do,
[Code]....
View 3 Replies
Similar Posts:
Nov 23, 2009
I have created a flash app in which there is a circle with circles plotted along it's circumference, it is rotated when the mouse is moved up or down. The rotation is drawn directly from the y position of the mouse pointer. What I would like to do is grade the movement some how so that the further down the mouse pointer goes the less impact on rotation the movement has.
My current code is like this:
myCircle.rotationZ = e.localY;
Is there some form of math formula I could use which would reduce the amount of rotation the greater the y position of the mouse position?
View 4 Replies
Apr 19, 2011
i create this code but i cant spinning it with mouse (when i hold it)
Code: Select allmthr.addEventListener(Event.ENTER_FRAME,rotate);
function rotate (e:Event)
{[code]....
View 3 Replies
Jun 18, 2009
My situation like this:IHost.as:
Code:
public interface IHost {
function doSomething() : void;
[code]....
View 2 Replies
Mar 11, 2010
I have a papervision camera of which turns using keyboard input, I have a radar of which I would like to orientate to direction when the camera turns.I have it all working apart from mapping my (camera) DisplayObject3D.rotationY to RadarInterface.rotation correctly.The camera (or any 3d object) works with values I'm finding hard:Clockwise: 0 to 89, 89 to 0, -0 to -89, -89 to -0 doing a complete 360.So if I were to turn 180 degrees I'd go from 0 to 90 and back down to 0 again.
View 1 Replies
Apr 17, 2009
i was wondering if theres a way to link the amount and direction of an objects rotation to the mouse position. I want it so if you move the mouse far to the left the object spins fast anticlockwise but if you move it to the center it stops.
View 2 Replies
Aug 15, 2009
I have done the rotation bit, but now i want to limit the rotation but i can't do it
this is my code -
PHP Code:
stage.addEventListener(Event.ENTER_FRAME, moveArm)
function moveArm(e:Event):void
[code].....
View 2 Replies
Feb 1, 2010
How do I rotate an object with the mouse after I have dragged the object with mouse.ssentially, I want to move the object with the mouse and then rotate it with another mouse click. Right now the object is moving and rotating at the sime time.
View 6 Replies
Jul 21, 2009
I want to know if there is a way to determine the rotation of mouse movements flawlessly. this will trace the direction I am going in.
[Code]...
View 2 Replies
May 31, 2011
My goal is to make it so that when the user clicks and drags the disc (whether it be click anywhere on the stage or clicking on the disc itself), the disk will turn according to where the mouse goes.
I've used this tutorial [URL] to make a simple arrow move when the mouse does to test the code and see if it works, and it does. But now i'm trying to figure out how to make it so it will only move when I drag the mouse. I've tried things like "onClipEvent (mouseDown)" and such but they don't drag the clip.
how to get the arrow/disc to drag (and eventually, play a sound, but I will worry about that later),
code on MC:
Code:
onClipEvent (mouseMove) {
x = this._xmouse;
y = this._ymouse*-1;
[Code]....
View 0 Replies
Aug 29, 2009
I've got a very simple AS2 test file here:URL...I have a simple triangle, and it follows the mouse as it moves around.I'd like to get the triangle to change rotation, to follow the mouse, but my so far bodged version doesn't do that very elegantly.I have this AS on the MC that follows the mouse:[code]
View 3 Replies
Nov 8, 2009
I'm not really replacing the mouse cursor exactly. Just placing a custom image of a pointer below it so it will follow the mouse cursor as it moves around the screen. I want this pointer image to move with the mouse and to rotate and point in the direction the mouse is traveling. Simple stuff. The problem is that the rotation of the pointer graphic is not smooth at all. It is jumpy and somewhat erratic particularly at slower mouse speeds. When the mouse is moving quickly the problem seems to go away.
PHP Code:
package {
import flash.display.Sprite;
import flash.events.*;
public class MouseFollower extends Sprite {
private var pointer:Pointer = new Pointer(); // ...a simple triangle mc
[Code] .....
View 2 Replies
Sep 30, 2009
I have a circle wheel i want to rotate and the speed should be based on the mouse position. I also need to have easing in and out.
When the user hovers over the bottom of the circle it will begin to rotate one way and then th top of the circle would make it rotate the other way. The further to the top or bottom they are the quick it spins. It ideally needs to ease in and out when it starts and stops when the user moves the mouse away.
The circle will be the complete movie so 50% top and bottom each for each direction.
View 1 Replies
Aug 6, 2011
The player rotates to the mouse when you click somewhere and moves there. The problem is sometimes when you click on a corner the player rotates towards where you clicked but sometimes starts moving sideways.
View 3 Replies
May 8, 2009
I'm trying to make a movieclip rotate around it's center (this is no problem since the center will never change). The problem that I am having is when I press the movieclip, in let's say the bottomright corner, and move the mouse the movieclip flips to a certain angle depending on my mouseposition. After the weird flip it works fine but it's the initial mouse click that makes the movieclip flip to an angle.I've tried playing around with different values to substract or add the starting angle but eveytime the result is not what i am looking for.Current code:
Code: Select all
package
{
[code].....
View 8 Replies
Jul 21, 2006
how to use trig to rotate a movie clip based on (my_mc._x, my_mc._y) and (_root._xmouse, _root._ymouse)?
View 1 Replies
Jun 14, 2007
I'm trying to make it ease to the spot but it doens't seem like there is a way.
It is jumpy, i would like to it to slowly smooth to the current mouse location. It's going to be used for a touch screen
Heres my current AS:
Code:
stop()
face.onRollOver = function(){
startDrag("mouseTarget", true);
[Code]....
View 1 Replies
Sep 12, 2009
I am trying to create a effect using AS3. The effect is that several arms should rotate towards the mouse, and rotate less when their further away from the mouse cursor.using Math.atan2 to find how much the arm nedd to rotate to point against the mouse, and then substract the distance from the mouse.(look at the following picture) For example, if Math.atan2 returns 100 and the distance from the mouse is 40, the arm would rotate 60. Thats what i thought.But i cant get it to work. I attached the source files if you want to help Note:A blue ring in the source file indicates the distance.
View 2 Replies
Apr 29, 2010
I have this code is AS3
Code:
var xMouse = mouseX;
var yMouse = mouseY;
[Code]...
But unfortunately, the ship does not follow mouse rotation. The ship only rotates with respect to the mouse when you move the ship, not when you move the mouse.
View 1 Replies
Jan 24, 2011
I have researched all over and have found some that "kind of" work, but the coding always has issues with CS3 (my version). I am more proficient in AS2, but would be willing to try AS3 if that is the way to go.I need a script that will allow the user to use their mouse to drag a wheel that will slow down to a stop. Think "Wheel of Fortune" style. Where it stops will trigger an event.
View 4 Replies
Jun 25, 2010
Essentially what I'm trying to do is nearly the same as this: http:[url].......However I'd like to ease/tween the movieclip position and rotation to the mouse position.The main issue I see is trying to get the current movieclip rotation and the target rotation,then tween it cockwise or counterclockwise from current to target.The way a movieclips rotation uses positive and negative numbers throws it off.If you just want to lock the mc rotation to the mouse rotation its fine, but once you try to tween it you run into difficulties. So the end effect would be like if you were to draw imaginary clockwise circles around the object, it should just keep rotating clockwise towards the mouse. Then if you started going counter clockwise it should just keep easing counter clockwise to the mouse.
View 1 Replies
Aug 16, 2005
First off, lemme start by saying that this site is incredibly awesome. Every time I have a problem or wish to learn something in Flash I turn to [URL]. Now for my problem. Have you ever played Madness? You know how, depending on where the mouse is, the hand rotates i.e. points at the mouse's current position? Well, I want to learn how to do that. I've attached a short animation demonstrating what I want to be able to do (the arrow points at the mouse's position, and then gun represents the movie clip that rotates) using a script
View 6 Replies
Nov 30, 2009
I have created a globe that rotates with no problem, but what I am trying to do is to control the direction of the rotation based on the mouse position. For example, if the mouse is to the right of the globe, it rotates towards the right and if the mouse in on the left, the globe rotates left. When the mouse is over the globe, it should stop.
View 1 Replies
Jun 25, 2010
I'd like to ease/tween the movieclip position and rotation to the mouse position.The main issue I see is trying to get the current movieclip rotation and the target rotation, then tween it cockwise or counterclockwise from current to target. The way a movieclips rotation uses positive and negative numbers throws it off. If you just want to lock the mc rotation to the mouse rotation its fine, but once you try to tween it you run into difficulties. So the end effect im looking for would be like if you were to draw imaginary clockwise circles around the object, it should just keep rotating clockwise towards the mouse. Then if you started going counter clockwise it should just keep easing counter clockwise to the mouse.
View 3 Replies
May 9, 2011
i create stage Mouse Rotation Y is complete and i want to put some easing on movieclip this is my code
Code:
import flash.events.Event;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
[Code]...
View 3 Replies
Jan 5, 2011
I have a Cube which I want to rotate using mouse motion. So if I move my mouse to the left it rotates as if rotationX was increased. When I move right rotationX is increased. Moving Up and Down alters rotationY.
This looks fine as long as you modify only one dimension (either rotationX or rotationY). But if I have already changed rotationX and then try to modify rotationY the results are weird. If rotationX is 180 rotationY effects are reversed. It basically is quite unpredictable and certainly not suitable for user.
I have tried to look around (failed), read about quaternions (couldn't understand), tried some out of blue and very complex trigonometric calculations (made a fool out of myself) and so I am stuck now. I've found this SO question Best way to translate mouse drag motion into 3d rotation of an object but it doesn't help me a bit, I can't understand any of the answers, really.
View 1 Replies
Jan 22, 2011
I have an object, the center of the object I believe is the rotation point. When I click transform and edit the rotation properties on the right side to like 55 degrees then it works, it rotates from the point it's suppose to and looks great. The problem is when I use AS .rotation on the object, I have no idea where it's rotating from and it's going all over the freaking place. I assumed it would rotate from the same rotation point as the transform tool rotates the object from. I also assumed 0-360 was the options for rotation. What am I doing wrong? from the looks of it's odd rotation I can't even tell where it's centering.
View 3 Replies
Nov 16, 2009
I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times.I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase.Here is the AS which controls a blank movieclip;
var sp:Sprite = new Sprite();
orb1.addChild(sp)
var g: Graphics =sp.graphics
[code]....
View 1 Replies
Nov 16, 2009
This is for a personal art project, however I have hit a potential (Actionscript) brick wall! I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times. I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase. Here is the AS which controls a blank movieclip;
[Code]...
View 5 Replies
Mar 28, 2011
I need to move between (rotated) object in flex along x, y, or z as an independent observer. The movement relative to x, y works ok, but when I go along the z axis, the observer behaves as it was apart of the xyz system of the objects and doesn't go straightforward to the object but in diagonal for example. Here is some tryout code
[Code]....
View 1 Replies