[SOLVED] this.entity.forward.clone() not working

I am making a third person sonic game and when I use this.entity.right.clone for movement it works perfectly but when I use this.entity.forward.clone the character goes up and down instead of forwards and backwards. The controls of the game are arrow keys to turn and WASD to move. This is the code

var Sonicmovement = pc.createScript('sonicmovement');

// initialize code called once per entity
Sonicmovement.prototype.initialize = function() {

};

// update code called every frame
Sonicmovement.prototype.update = function(dt) {



if(this.app.keyboard.isPressed(pc.KEY_W)){
var impulse = this.entity.forward.clone();
impulse.scale(1);
this.entity.rigidbody.applyImpulse(impulse);
}

if(this.app.keyboard.isPressed(pc.KEY_S)){
var impulse = this.entity.forward.clone();
impulse.scale(-1);
this.entity.rigidbody.applyImpulse(impulse);
}

if(this.app.keyboard.isPressed(pc.KEY_A)){
var impulse = this.entity.right.clone();
impulse.scale(1);
this.entity.rigidbody.applyImpulse(impulse);
}

if(this.app.keyboard.isPressed(pc.KEY_D)){
var impulse = this.entity.right.clone();
impulse.scale(-1);
this.entity.rigidbody.applyImpulse(impulse);
}

if(this.app.keyboard.isPressed(pc.KEY_RIGHT)){
    this.entity.rigidbody.applyTorque(0,-2,0)
}

if(this.app.keyboard.isPressed(pc.KEY_LEFT)){
    this.entity.rigidbody.applyTorque(0,2,0)
}
};

And this is the project link: Sonic

Hi @Justin_Ibeawuchi and welcome,

Your project seems to be private and we can’t access it.

Forward is the negative Z local direction of the entity, so you may have to rotate/adjust your player’s looking direction to get what you are looking for.

thank you. i realized my sonic model was oriented wrong :sweat_smile:

1 Like