dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: rotate to angle alignment problem

  1. #1
    Member
    Join Date
    Jun 2003
    Posts
    76

    rotate to angle alignment problem

    please check out:
    http://ize.badne.ws/stuff/walker.swf

    i want the cannon to be aligned perfectly with the crosshair but i can't figure out what to change so it works

    and if anyone has an idea how to play the walking animation backwards that would be great to know too

    here's the fla(80kb)
    http://ize.badne.ws/stuff/walker2.fla

    thanks in advance

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I was able to simplify your onEnterFrame handler by using a few trig functions.

    // USEFUL CONSTANTS
    kCorrection = 180; // This is only needed because your cannon is pointing to
    // the left in it's 'rest' position - if you fix it to point
    // to the right, you can set kCorrection to 0 (omit it).
    kRadiansToDegrees = 180/Math.PI;


    onEnterFrame = function()
    {
    origin = {x:0,y:0};

    _root.player.body.kopf.localToGlobal(origin);

    // get the origin position
    dist_x = _root._xmouse - origin.x;
    dist_y = _root._ymouse - origin.y;

    direction = Math.atan2(dist_y, dist_x) * kRadiansToDegrees;
    _root.player.body.kopf._rotation = direction+kCorrection;

    // not required for this example
    // but may be useful
    // determine x and y movements for a bullet to go from origin to mouse
    xmov = Math.cos(direction);
    ymov = Math.sin(direction);

    }

    - jim

  3. #3
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    For the first question, you should use localToGlobal.
    Second question.
    You should remove stop() from the 14-th frame of the "player" and the code on the "player"
    should be
    Code:
    onClipEvent (enterFrame) {
    	stop();
    	if (Key.isDown(Key.LEFT)) {
    		this.play();
    		this._x-=4;
    	}
    	if(Key.isDown(Key.RIGHT)){
    		this._x+=4;
    		if(_currentframe>1){
    			prevFrame();
    		}else{
    			gotoAndStop(23);
    		}
    	}
    }
    Ups, I see that Jbum unswered the first question more detaled

  4. #4
    Member
    Join Date
    Jun 2003
    Posts
    76
    thanks this helped me alot guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center