A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] Gravity/Ground and Walls

Hybrid View

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    13

    [F8] Gravity/Ground and Walls

    New to flash and I'm having some trouble making gravity and having things not go through barriers and walls. I'm using something like " if (this.hitTest(getBounds(_root).xMax, _y, true)) {
    _x -= hitback; hitground = true;
    }" and its not so good. Sometimes you can fall through the ground and sometimes you bounce. Could anyone give me a script on Walls and gravity and maybe explain it?

  2. #2
    God yeps's Avatar
    Join Date
    Dec 2005
    Location
    :noitacoL
    Posts
    660
    for gravity you should just do...

    if(this._y>400){
    this.__y = 400
    }

    then for walls, you should do something like...

    if (this.hittest(_root.wall)){
    this._x -= 2
    }

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Posts
    13
    Eh, wouldn't that just make it so the player was always at _y 400? (and I already have that for my walls) but is there any other ways without having the player bounce back off the walls so that he doesnt go through?

  4. #4
    Member
    Join Date
    Apr 2006
    Posts
    32
    Quote Originally Posted by yeps
    for gravity you should just do...

    if(this._y>400){
    this.__y = 400
    }

    then for walls, you should do something like...

    if (this.hittest(_root.wall)){
    this._x -= 2
    }
    i don't think that this script would work if the player would be from the right side of the wall, than if he hits the wall from the right side it will go through the wall and go on the other side (i don't think that you want this )
    i would make it so:
    you could create to statements leftmove and rightmove, when for example leftmove="true" the player can move left the same to the right move and simply when you hit the wall from the right side the wall makes
    player.leftmove="false" so there happens an animation of running but the player is neither moving left nor bouncing

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