-
lemon juice hurts your eyes
Rotate MC following parabolic path
Alright, so I found this code somewhere on FK and I've converted it to AS3 and it seems to work correctly:
Code:
var startx:Number = mc.x; // starting position
var endx:Number = stage.stageWidth - mc.width; // ending position
var starty:Number = mc.y; // starting altitude
var travel_height:Number = 600; // travel height
var duration:int = 3*1000; // duration of travel in milliseconds
var startTime:Number = getTimer(); // starting time (now) in milliseconds
mc.addEventListener(Event.ENTER_FRAME, jump);
function jump(e:Event):void
{
// convert current time to an animation ratio (r) from 0-1
var r:Number = (getTimer()-startTime)/duration;
// we will use 'r' to control everything in the animation
// stop animating when we reach 1
if (r >= 1)
{
r = 1;
mc.removeEventListener(Event.ENTER_FRAME, jump);
}
// use r to determine horizontal coordinate
mc.x = startx + r*(endx-startx);
// use r as input to Math.sin() - scaling to 0-PI
// using value of Sin to make vertical motion
mc.y = starty - Math.sin(r*Math.PI)*travel_height;
}
This tweens a MovieClip from a starting point to an ending point following the curve of a parabolic function.
What I would like to do, is rotate the mc while moving it. Imagine a horse jumping over a ledge, when it starts its front legs are aimed upwards, but when landing, they will point downwards.
The MC I'd like to move will be a jumping animal of some kind, so the movement has to be spread out just right so it starts facing upwards, then levels when the function hits its top-most point and then start rotating downwards again.
Hope this makes sense
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|