So I've been playing around with it some more and been getting a
little closer. But its still a ways off. The biggest issue with this
demo is that the plane catches the mouse before I reach the edges of
the map. I'm not sure what I can do next but thats where I am now. Its
funny to. About 20 mins after I posted this I decided to bite the
bullet and buy Keith's book. I'm going to open it tonight and see
where it gets me. If you guys have any more ideas please let me know!
Thanks!

What I've come up with so far is something like this...

var speed:Number = 2;
var turnRate:Number = .3;
var agroRange:Number = 500;

var moveX:Number = 0;
var moveY:Number = 0;
var distanceTotal:Number;

//stage vars
var minXMove:Number = 0;
var minYMove:Number = 0;
var maxXMove:Number = (levelMap.width - stage.stageWidth) * -1;
var maxYMove:Number = (levelMap.height - stage.stageHeight) * -1;

function movemap():void {

        
        //move on x-axis
        levelMap.x -= (moveX * 2);
        
        if (levelMap.x >= minXMove) {
                levelMap.x = minXMove;
                //speedX *= -1;
        }
        if (levelMap.x <= maxXMove) {
                levelMap.x = maxXMove;
                //speedX *= -1;
        }
        
        
        //move on y-axis
        levelMap.y -= (moveY * 2);

        if (levelMap.y >= minYMove) {
                levelMap.y = minYMove;
                //speedY *= -1;
        }
        if (levelMap.y <= maxYMove) {
                levelMap.y = maxYMove;
                //speedY *= -1;
        }
}





stage.addEventListener(Event.ENTER_FRAME, doFollow2);

//
// doFollow(follower, target)
// use ex: doFollow(myEnemyMovieClip, playerMovieClip)
//
function doFollow(e:Event) {
        
        //calculate distance between follower and target
        var distanceX:Number = mouseX - plane.x;
        var distanceY:Number = mouseY - plane.y;
        
        //get total distance as one number
        distanceTotal = Math.sqrt((distanceX * distanceX) + (distanceY * 
distanceY));
        
        //check if target is within agro range
        if(distanceTotal <= agroRange){
                //calculate how much to move
                var moveDistanceX:Number = turnRate * (distanceX/distanceTotal);
                var moveDistanceY:Number = turnRate * (distanceY/distanceTotal);
                
                //increase current speed
                moveX += moveDistanceX;
                moveY += moveDistanceY;
                
                //get total move distance
                var totalmove = Math.sqrt(moveX*moveX+moveY*moveY);
                
                //apply easing
                moveX = speed * (moveX/totalmove);
                moveY = speed * (moveY/totalmove);
                
                //move follower
                plane.x += moveX;
                plane.y += moveY;
                
                //rotate follower toward target
                plane.rotation = 180*Math.atan2(moveY, moveX)/Math.PI;
                
                movemap();
                
        }       
        
}

On Mon, Jan 26, 2009 at 1:46 PM, Todd Kerpelman <t...@kerp.net> wrote:
> Well, again, don't know how much this will help you, but in the past when
> I've done a "camera following a moving object with a scrolling background",
> I've attached a virtual spring from my camera to the position I want to go
> to and then just let the spring drag my camera to the right place. If you
> put on some pretty heavy damping, it ends up looking pretty good, and I
> don't have to think about angles. :)
>
> Your spring code would probably look something like this...
>
> private function onEnterFrame(e:Event):void
> {
>
> var accelX:Number = (_pointToFollow.x - this.x) * _k;
> var accelY:Number = (_pointToFollow.y - this.y) * _k;
> _velX += accelX;
> _velY += accelY;
> this.x += _velX;
> this.y += _velY;
> _velX *= _damping;
> _velY *= _damping;
>
> }
>
> You probably want _k to be something in the .1 range, and _damping to be in
> the .75 range. All of this assumes, by the way, that you're not rotating the
> camera to match the rotation of the plane.
>
> But the book Jason recommended might have better ideas. I haven't read it
> yet.
>
> --T
>
>
>
> On Sun, Jan 25, 2009 at 1:15 PM, Corban Baxter <corb...@gmail.com> wrote:
>
>> thanks todd. thats what I have been doing for the most part. I'm
>> working on figuring out how to move the Camera sprite around on an
>> angle.
>>
>> i've got script that makes the airplane point towards the mouse at all
>> times. but thats the easy part. now i need the Camera sprite to move
>> at a consistent rate at the same angle the plane is pointing. Just
>> can't see to figure out what it take to do that.
>>
>> var minXMove:Number = 0;
>> var minYMove:Number = 0;
>> var maxXMove:Number = (levelMap.width - stage.stageWidth) * -1;
>> var maxYMove:Number = (levelMap.height - stage.stageHeight) * -1;
>>
>> stage.addEventListener(Event.ENTER_FRAME, pointAtCursor);
>>
>> function movemap():void {
>>
>>
>>        //move on x-axis
>>        levelMap.x += speedX;
>>
>>        if (levelMap.x >= minXMove) {
>>                levelMap.x = minXMove;
>>        }
>>        if (levelMap.x <= maxXMove) {
>>                levelMap.x = maxXMove;
>>        }
>>
>>
>>        //move on y-axis
>>        levelMap.y += speedY;
>>
>>        if (levelMap.y >= minYMove) {
>>                levelMap.y = minYMove;
>>        }
>>        if (levelMap.y <= maxYMove) {
>>                levelMap.y = maxYMove;
>>        }
>> }
>>
>> function pointAtCursor(e:Event) {
>>
>>        // get relative mouse location
>>        var dx:Number = mouseX - plane.x;
>>        var dy:Number = mouseY - plane.y;
>>        speedX = (dx * -1);
>>        speedY = (dy * -1);
>>
>>        // determine angle, convert to degrees
>>        var cursorAngle:Number = Math.atan2(dy,dx);
>>        var cursorDegrees:Number = 360*(cursorAngle/(2*Math.PI));
>>
>>        // point at cursor
>>        plane.rotation = cursorDegrees;
>>
>>        plane.x -= (plane.x-mouseX) / 6;
>>        plane.y -= (plane.y-mouseY) / 6;
>>
>>        movemap();
>>
>> }
>>
>> the hard part is getting the speedX and speedY to be numbers that
>> don't cause the map to fly to fast. Just not sure where to go from
>> here.
>>
>>
>>
>>
>> On Sun, Jan 25, 2009 at 2:42 PM, Todd Kerpelman <t...@kerp.net> wrote:
>> > Well, I'm no plane game expert, but here's probably how I'd approach
>> it...
>> >
>> > Within your PlaneGame movie, create a child sprite called Camera.
>> >
>> > Make all your interface stuff children of the PlaneGame movie. But make
>> the
>> > background, your plane, the enemies, etc, all children of this Camera
>> child
>> > sprite.
>> >
>> > Then, when it comes to creating the "background scrolling below you"
>> look,
>> > don't have your background move at all. Only have the things that would
>> > actually move in real life (planes and tanks and whatever) move.
>> >
>> > Instead, make your Camera sprite scale and/or move itself to track your
>> > plane (or, even better, a point a couple hundred pixels in front of your
>> > plane.) That will make it look like the background is moving, but it's
>> > really staying in place. And it will simplify your planes and tanks and
>> > bullets, because you can basically just look at each sprite's position
>> and
>> > velocity, without having to try and somehow compensate for a magical
>> moving
>> > background.
>> >
>> > For development purposes, by the way, I would start your game by not
>> having
>> > the camera move at all, and just making sure everything works right in a
>> > tiny little world the size of your screen. Once that's working, then you
>> can
>> > enlarge the bounds of your world and start moving your camera around.
>> >
>> > Good luck!
>> >
>> > --T
>> >
>> >
>> >
>> > On Sun, Jan 25, 2009 at 11:16 AM, Corban Baxter <corb...@gmail.com>
>> wrote:
>> >
>> >> hey guys! I'm trying to build a simplified version of
>> >> http://www.miniclip.com/games/skies-of-war/en/. Mostly looking to
>> >> replicated the movement. But I have no ideas on where to start. I'm
>> >> having alot of trouble setting the angles correctly to give the
>> >> background a constant speed but allowing it to change angles. I
>> >> understand its going to be based on the planes current angle. But
>> >> that's where I get confused on getting the speeds to not over lap and
>> >> making it seem like it moving faster. Ok I'm rambling now. but I was
>> >> hoping someone might be able to help me understand this better and
>> >> give me some examples I could use to get moving. Any help would be
>> >> great! thanks!
>> >>
>> >> --
>> >> Corban Baxter
>> >> http://www.projectx4.com
>> >> _______________________________________________
>> >> Flashcoders mailing list
>> >> Flashcoders@chattyfig.figleaf.com
>> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>> >>
>> > _______________________________________________
>> > Flashcoders mailing list
>> > Flashcoders@chattyfig.figleaf.com
>> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>> >
>>
>>
>>
>> --
>> Corban Baxter
>> http://www.projectx4.com
>> _______________________________________________
>> Flashcoders mailing list
>> Flashcoders@chattyfig.figleaf.com
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
Corban Baxter
http://www.projectx4.com
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to