Trouble with getLocalPosition

Hey so I’m a beginner, and what i’m trying to do is make it so that when it goes past a certain x position it will reset back to its original position. the script itself works but the condition doesn’t anyone got any help?

//Puckcontroller.prototype.update = function(dt) {
    if (Math.abs(Math.round(this.entity.getLocalPosition().x)) > 1 || Math.abs(Math.round(this.entity.getLocalPosition().y)) > 1) {
        this.entity.rigidbody.isActive = false;
        this.entity.setPosition(0, 0, 0);
        this.entity.rigidbody.isActive = true;

Hi @Michael_Unknown and welcome,

You could try and use a console.log to print the local position the console and see what values you are getting.

Usually if you are trying to target a world point then you may have to use getPosition instead.

If you keep having trouble try sharing a sample project that reproduces the issue to take a look.


I use a school issued chromebook to program which doesn’t allow you to view the console and I realize that getLocalPosition is usually for finding your position relative to the entities parent but I had a null parent at the center to see if that would work. fortunatly I did end up finding out an alternative to fix the problem. I was using a rigidbody which apparently doesn’t work with setPosition, so instead I used:
this.entity.rigidbody.teleport(0, 0, 0);
this ended up working for me but thanks for your help anyways.

1 Like