[SOLVED] Problem in movement script

Here is my project:
here is the code for the script (movement.js):

var Movement = pc.createScript('movement');

// initialize code called once per entity
Movement.prototype.initialize = function() {
    this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
    this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);

// update code called every frame
Movement.prototype.update = function(dt) {
    var position = this.entity.getPosition();
    var forward = true;
    if (forward === true){
        this.entity.rigidbody.teleport(position.x + 0.078, position.y, position.z);
    if (this.app.keyboard.isPressed(pc.KEY_A)) {
        this.entity.rigidbody.teleport(position.x, position.y, position.z - 0.1);
       if (this.app.keyboard.isPressed(pc.KEY_D)) {
        this.entity.rigidbody.teleport(position.x, position.y, position.z + 0.1);

// swap method called for script hot-reloading
// inherit your script state here
// Movement.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/

I am getting this error:

I create a variable called “forward” and it is always set to true. The issue is with the teleport function on the if statement that moves the entity (in this case the main character) forward. I might be not assigning “entity” to the “player” in the hierarchy, but it says the issue is reading the teleport function. Any help would be much appreciated, as this is a project due in a few days. thank you!

this is the if statement that cannot be read.

Hi @CRAYPHiSHQUESTIONS! Has the entity a rigidbody component?

Oh haha, silly me. I was deleting the rigid body component from the walls and enemies because it interfered with the collision script, and I must have accidentally done it with the player entity too. Thanks so much, it’s the little mistakes that get you.

1 Like