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); } }
-
You probably want to make the platform
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.
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.)
-
@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
(update
function). There's a call toFlxG.collide
with twoFlxGroup
objects, each with a bunch of things with aFlxSprite
in them.Please let me know if you prefer that I create some sort of MVP with the problem.
-
I can't tell 100% because of the ECS indirection layers, but it looks like you're modifying
x
andy
of the playerFlxObject
directly inKeyboardInputComponent
? That way, you're bypassing Flixel's physics, you should usevelocity
instead.
-
@Gama11 said in Disable Physics - Platform is effected ny player.:
[...] it looks like you're modifying
x
andy
of the playerFlxObject
directly inKeyboardInputComponent
? That way, you're bypassing Flixel's physics, you should usevelocity
instead.I switched over and this now works. Thanks!