Sprite going back:Help

im trying to make a sprite go somewhere, but when i hit an arrowkey, the sprite goes back to where it was

update: function (dt) {
            var a = a;
            var b = b;
            var c = c;
           var thing = app.root.findByName('pointer');
            var port = thing.getPosition();
            var command = null;
            if(app.keyboard.wasPressed(17)){
                command = prompt('Type your command.','');
                switch(command){
                        case('10110'): this.entity.translate(port.x,port.y,0);
                        break;
                }
            }
            
        }//no touch

It would be easier to debug this if you posted a simple reproducible scene that demonstrates the problem.

https://playcanvas.com/editor/scene/653110 project link
hit ctrl then type 10110. do it twice

I believe the problem is because you’re calling setPosition on an entity that has a dynamic rigidbody component. If you do this, the physics simulation is not being told that they rididbody needs to be relocated. So instead of calling setPosition, call pc.RigidbodyComponent#teleport:

https://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#teleport

thx, i was doing a jam PS: is there a way to lock rotation?

For physics? Set the angular factor on the rigid body to 0.

The code for doing that is -

this.entity.rigidbody.angularFactor = pc.Vec3.ZERO;

1 Like