PlatformObjects keys with Javascript

Hi!
How can I manipulate the behavior “PlatformObject” using a javascript code event?
This is what I make but it does not work when I add the action for simulate Keys for movement. I’ve just follow what it is in the wiki docs.
I will appreciate any ideas.

const player = runtimeScene.getObjects(“PlayerGreen”);
const playerHitBoxes = runtimeScene.getObjects(“PlayerHitBox”);
const player1 = player[0];

const platformerBehavior = playerHitBoxes[0].getBehavior(“PlatformerObject”);

if (platformerBehavior.isJumping() || platformerBehavior.isFalling()){
player1.setAnimation(1);
} else if (platformerBehavior.isOnFloor()) {
if (!platformerBehavior.isMoving()) {
player1.setAnimation(0);
} else {
player1.setAnimation(2);
};
};

var LEFTKEY = 37;
var RIGHTKEY = 37;
if (runtimeScene.getGame().getInputManager().isKeyPressed(LEFTKEY)) {
player1.flipX(true);

} else if (runtimeScene.getGame().getInputManager().isKeyPressed(RIGHTKEY)) {
player1.flipX(false);
}

if (keyboard.isKeyPressed(LEFTKEY)) {
** playerHitBoxes.simulateLeftKey**
}
//JUMP (?)
/if(runtimeScene.getGame().getInputManager().isKeyPressed(Spacebar)){
** playerHitBoxes._jumpKey = true;
*

The Platformer Character and Platform Objects are a behavior rather than native events, and may or may not be accessible via Javascript. Others may be able to chime in to confirm.

However, javascript isn’t the first class language in the engine, the event system is, is there a reason why you’re recreating the platformer character events via JS rather than just using those events?

Hi, thanks for the answer.
It is to program the game to connect to devices such as Smartwatchs, that is why I wanted to use the simulate keys on JS events to avoid using the default controls of the PlatformObjects Behavior.

https://docs.gdevelop-app.com/GDJS%20Runtime%20Documentation/PlatformerObjectRuntimeBehavior.html#simulateControl

1 Like