Disable Physics - Platform is effected ny player.



  • Hello good people of Haxeflixel forum.

    I am kind of new here so I will try to post as much relevant questions as possible.

    I am in the processes of learning Haxeflixel as deep as I can, and trying everthing that I can.
    in my Playstate I have a Player class which I have declered the gravity in it, and a platform that I made, but for some reason the platform is effect by the player gravity(when the player lands on the platform, it gets pushed by the player).

    am I doing something wrong? is there a way to turn the platform kinematic? thank you.

    the code of the playstate is attached here :

    import flixel.FlxSprite;
    import flixel.FlxState;
    import flixel.FlxG;
    import  flixel.group.FlxGroup;
    import flixel.util.FlxColor;
    
    class PlayState extends FlxState
    {
    	var player:Player;
    	var platforms:FlxGroup;
    	override public function create():Void
    	{
    		platforms = new FlxGroup();
    		
    		var floor = new FlxSprite();
    		floor.makeGraphic(FlxG.width, 100, FlxColor.BLUE);
    		floor.x = 0;
    		floor.y = FlxG.height - 30;
    		platforms.add(floor);
    		floor.acceleration.y = 0;
    		
    		add(platforms);
    		
    		super.create();
    		player = new Player(10, 10);
    		add(player);
    	}
    
    	override public function update(elapsed:Float):Void
    	{
    		super.update(elapsed);
    		FlxG.collide(platforms, player);
    	}
    }
    

  • administrators

    You probably want to make the platform immovable:

    http://api.haxeflixel.com/flixel/FlxObject.html#immovable



  • Immovable solved half the problem for me (I'm not using gravity) -- the player/wall collide, but the player can "push" through the wall. i.e. if there's a wall on the left, and I hold down the left button for about a second, the player eventually makes it through.

    alt text

    How do I fix this? Is it related to this issue about pixel-perfect overlap? (I'm using sprites filled at runtime with solid-colour pixels.)


  • administrators

    @ashes999 Can you share some code to reproduce that?



  • @Gama11 certainly. My GitHub repo (up to date) is here. It's non-trivial (you have a sub-repository for turbo which contains all the code).

    I don't want you to spend ages trying to figure out my code, so you can check out code/source/turbo/ecs/TurboState.hx (updatefunction). There's a call to FlxG.collide with two FlxGroup objects, each with a bunch of things with a FlxSprite in them.

    Please let me know if you prefer that I create some sort of MVP with the problem.


  • administrators

    I can't tell 100% because of the ECS indirection layers, but it looks like you're modifying x and y of the player FlxObject directly in KeyboardInputComponent? That way, you're bypassing Flixel's physics, you should use velocity instead.



  • @Gama11 said in Disable Physics - Platform is effected ny player.:

    [...] it looks like you're modifying x and y of the player FlxObject directly in KeyboardInputComponent? That way, you're bypassing Flixel's physics, you should use velocity instead.

    I switched over and this now works. Thanks!


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.