PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Make Charater face mouse platform
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Make Charater face mouse platform

  1. #1
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,029

    Make Charater face mouse platform

    Hi, I have my as2 code for my game im making so far the char can jump and move left and right. But the problem is I need help to make him face the mouse like lets say my mouse is to the x- of my character than I would want his left facing movie clip (which I havent made yet) to be facing that way etc. Anyone know where I could start heres what I have:
    Actionscript Code:
    onClipEvent (load) {
    var ground:MovieClip = _root.ground;
    var grav:Number = 0;
    var gravity:Number = 2;
    var speed:Number = 7;
    var maxJump:Number = -12;
    var touchingGround:Boolean = false;
    }
    onClipEvent (enterFrame) {
    _y += grav;
    grav += gravity;
    while (ground.hitTest(_x, _y, true)) {
    _y -= gravity;
    grav = 0;
    }
    if (ground.hitTest(_x, _y+5, true)) {
    touchingGround = true;
    } else {
    touchingGround = false;
    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    }
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    }
    if (Key.isDown(Key.UP) && touchingGround) {
    grav = maxJump;
    }
    if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
    _x -= speed;
    }
    if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
    _x += speed;
    }
    if (ground.hitTest(_x, _y-(height), true)) {
    grav = 3;
    }
    }
    That's the movement code that lets me move left and right and jump with gravity all I am asking is if anyone could basically help me with code to make the char face the mouse when to the left of it and right

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Inside your character movieclip, you probably have the bottom of the character on the registration point to make it look like he is ON the platform. Well, inside the character movieclip, make your character into another movieclip, and this time, the registration point in the center. Give this movieclip an instance name of player, and make sure his eye are what you want to follow, is drawn on the LEFT-side in the player movieclip. Finally, change your code for the character movieclip to this:

    Actionscript Code:
    onClipEvent (load) {
        var ground:MovieClip = _root.ground;
        var grav:Number = 0;
        var gravity:Number = 2;
        var speed:Number = 7;
        var maxJump:Number = -12;
        var touchingGround:Boolean = false;
    }
    onClipEvent (enterFrame) {
        _y += grav;
        grav += gravity;
        while (ground.hitTest(_x, _y, true)) {
            _y -= gravity;
            grav = 0;
        }
        if (ground.hitTest(_x, _y+5, true)) {
            touchingGround = true;
        } else {
            touchingGround = false;
        }
        if (Key.isDown(Key.RIGHT)) {
            _x += speed;
        }
        if (Key.isDown(Key.LEFT)) {
            _x -= speed;
        }
        if (Key.isDown(Key.UP) && touchingGround) {
            grav = maxJump;
        }
        if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
            _x -= speed;
        }
        if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
            _x += speed;
        }
        if (ground.hitTest(_x, _y-(height), true)) {
            grav = 3;
        }
        disX = this._x - _root._xmouse;
        disY = this._y - _root._ymouse;
        radians = Math.atan2(disY, disX);
        degree = radians*180/Math.PI;
        this.player._rotation = degree;
    }

    Hope it works
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,029
    that looks really great and it works the way you think im doing it but the thing is Im doing it with collisions that are already in blocks this is way too hard to explain I dont think I even know what to write :/

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