A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] Character cant stay in a straight line.

  1. #1
    Senior Member AzraelKans's Avatar
    Join Date
    May 2002
    Location
    Hell... with frequent access to heaven ;)
    Posts
    409

    [F8] Character cant stay in a straight line.

    Im trying to fix an old game where a character moves inside a straight line (sort like a high wire), however it is inside another movie. originally it used an angle, but I upgraded that to vector math (kudos to tonypa btw)

    The problem is as you move up and down, the character starts to move outside the line and to the right. is like the vector going up is diferent than the one going down. (the same problem ocurred with trigonometry btw)

    Heres is some parts of the code.

    Code:
    /*Maquinaria is the movieclip containing the whole high wire. clown is the character you move.*/
    //Cuadro1, cuadro2 are the beginning and end markers of the high wire.
    
    
    x1=maquinaria_mc.cuadro1._x
    y1=maquinaria_mc.cuadro1._y
    x2=maquinaria_mc.cuadro2._x
    y2=maquinaria_mc.cuadro2._y
    
    vx=x2-x1
    vy=y2-y1
    
    l=Math.sqrt(vx*vx+vy*vy)
    
    maquinaria_mc.brazo._y=cuadro1._x+vx*0.5
    maquinaria_mc.brazo._y=cuadro1._y+vy*0.5
    
    vx/=l
    vy/=l
    
    miax= vx*clownspeed;
    miay= vy*clownspeed;
    
    
    
    onEnterFrame=function(){
    			if (Key.isDown(Key.UP) && maquinaria_mc.brazo._y>-157) {
    				maquinaria_mc.clown._y -= miay;
    				maquinaria_mc.clown._x -= miax;
    			}
    			if (Key.isDown(Key.DOWN) && maquinaria_mc.brazo._y<55) {
    				maquinaria_mc.clown._y += miay;
    				maquinaria_mc.clown._x += miax;
    			}
    
    
    }
    Last edited by AzraelKans; 03-13-2008 at 12:55 PM.

  2. #2
    Senior Member AzraelKans's Avatar
    Join Date
    May 2002
    Location
    Hell... with frequent access to heaven ;)
    Posts
    409
    Just for the record, I fixed this by moving the character across the vector length instead of moving it by increments.

    maquinaria_mc.brazo._y=cuadro1._x+vx*dvx
    maquinaria_mc.brazo._y=cuadro1._y+vy*dvx

    //where dvx is a variable between 0 to 1 with increments of 0.01 per frame.

    Im still curious why the vector increment didnt worked. any ideas on that?

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