[SOLVED] Attribute problem

see my code

var MobileMovement = pc.createScript(‘mobileMovement’);

MobileMovement.attributes.add(‘player’,{type :‘entity’});

MobileMovement.prototype.initialize = function() {
this.entity.element.on(‘touchstart’,this.ontouchstart,this);
this.entity.element.on(‘mousedown’,this.ontouchstart,this);
};

MobileMovement.prototype.update = function(dt) {

};

MobileMovement.prototype.ontouchstart = function() {
this.player.rigidbody.applyImpulse(-0.1,0,0);
};

but it does not work when i press the button, so long for my mobile game

i even made the player a dynamic with a collision

Hi @jus.co_ding_me_23,

Check if your element component has the Use Input property set to true in editor.

what is that?

it’s a boolean under the element component

ok

use input is on

and it doesnt work

Start debugging your code, is it the callback not fired or maybe your applied impulse too small?

Add a console log and check in the browser console if your method is being actually fired:

MobileMovement.prototype.ontouchstart = function() {
   console.log('inside');
   this.player.rigidbody.applyImpulse(-0.1,0,0);
};

it works, thanks @Leonidas

1 Like