A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Movement

  1. #1

    Movement

    Hey guys, i'm new to flash 8, and i'm working on remaking a flash game called "Penguin Chat" for my website. I've got most of it done, but i need to make the character walk to the mouse click. I have an animation for walking in every angle, but i don't know how to play it and make the character move toward the mouse click. Also, i need to make the character rotate "tracking" the mouse position. And, i have a room with music that plays but i want it to stop when you leave the room. How do i do these things?
    Thanks!

  2. #2
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    To face mouse:-
    Code:
    xdiff = mouseX-penguin.x;
    ydiff = mouseY-penguin.y;
    penguin.rotation = Math.atan2(ydiff, xdiff)/(Math.PI/180) + 90;
    To move towards mouse:
    Code:
    //On click event
    function mclick(e:MouseEvent)
    {
    destX = mouseX;
    destY = mouseY;
    }
    
    //Enterframe or any update event
    function eframe(e:Event)
    {
     var dx:Number = this.x - destX;
     var dy:Number = this.y - destY;
     var dist:Number = dx*dx+dy*dy; //distance to destination
     if(Math.abs(dist)>speed)
     {
     this.x += moveSpeed * Math.cos(this.rotation * (Math.PI/180));
     this.y += moveSpeed * Math.sin(this.rotation * (Math.PI/180));
     }
    }
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  3. #3
    good, but how do i make the character change sprites? When i click i want him to do a walking animation to the click point.
    Thanks

  4. #4
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    I've got most of it done
    really? how much have you "actually" done till now?

    if the walking animation is on frame 2, on the timeline place, gotoAndStop(2)
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  5. #5
    about 70%. Also, i get this error when i put in the walking code:

    Code:
    **Error** Scene=Scene 1, layer=Layer 1, frame=109:Line 2: Statement must appear within on/onClipEvent handler
         function mclick(e:MouseEvent)
    
    **Error** Scene=Scene 1, layer=Layer 1, frame=109:Line 9: Statement must appear within on/onClipEvent handler
         function eframe(e:Event)
    
    Total ActionScript Errors: 2 	 Reported Errors: 2
    two more question (sorry) how do i start music in one room, and turn it off when you leave?
    And: when the penguin contacts a wall how can i get him to either stop or go to another room?

  6. #6
    Senior Member PRadvan's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    261
    Quote Originally Posted by 123kirby View Post
    about 70%
    So if making the character turn, making the character walk to the mouse, checking if character hit a wall, and playing/stopping music is 30%, I wonder, what's the other 70%?

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