Author Topic: [Beginners Question] Player standing on Top of each other  (Read 850 times)

lp

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Or how does overlap effect the sprites position and velocity?

What i have is this:

http://eco1221-11844.innterhost.net/flixel/HelloWorld.swf

2 player (wasd and arrow keys) and a map. Collision with the map works fine.
Now i would like that the players are able to stand on each other.

here's the code:
playstate.as

Code: [Select]
override public function update():void
        {
           
            _map.collide(_player1);
    _map.collide(_player2);
    _player1.collide(_player2);

player.as ( controls):

Code: [Select]
if(FlxG.keys.pressed(cLeft))
            {
                facing = LEFT;
                velocity.x -= _move_speed * FlxG.elapsed;
            }
            else if (FlxG.keys.pressed(cRight))
            {
                facing = RIGHT;
                velocity.x += _move_speed * FlxG.elapsed;               
            }
            if(FlxG.keys.justPressed(cUp) && velocity.y == 0)
            {
                velocity.y = -_jump_power;
            }
           
                if (velocity.y != 0)
                {
                    play("jump");
                }
                else
                {
                    if (velocity.x == 0)
                    {
                        play("stopped");
                    }
                    else
                    {
                       play("normal");
                    }
                }
     
if you jump one player on top of the other the animation changes between "jump" and "stopped" as does the velocity.y. also the controls get weird.
 how do i  get the top player to collide with the other like he collides with the floor? what exactly happens when the player collides with the floor?

i tried using the fixed attribute, but only to the effect of one player kicking the other through the floor.

thanks for any help

SysOp

  • Member
  • **
  • Posts: 53
  • Karma: +0/-0
    • View Profile
    • check my kick ass half-life mod!
Hey,

You can do checks on what you are standing on the function HitBottom(). So, you check if object is Player and if Player is on floor, then, you play X animation, else, another one.
Remember to also collide player 2 with player 1.
"Hope is not a dream, but a way of making dreams become reality"