Hey guys, I’ve been watching tutorials and looking at sample code and am attempting to create my first project with just a block that has gravity and can move with the arrow keys.
When it initially loads, the block falls down and hits the ground and bounces a little as expected.
Then I have the following script in the block object:
var Movetest = pc.createScript('movetest');
var keyboard = new pc.Keyboard(window);
// initialize code called once per entity
Movetest.prototype.initialize = function() {
// update code called every frame
Movetest.prototype.update = function(dt) {
if (keyboard.wasPressed(pc.KEY_RIGHT)){
this.entity.translateLocal(0.01,0,0);
}
if (keyboard.wasPressed(pc.KEY_LEFT)){
this.entity.translateLocal(-0.01,0,0);
}
if (keyboard.wasPressed(pc.KEY_UP)){
this.entity.translateLocal(0,-0.01,0);
}
if (keyboard.wasPressed(pc.KEY_DOWN)){
this.entity.translateLocal(0,0.01,0);
}
};
Now that works to move the block around the screen but if I walk off the ground, it doesn’t fall. Why doesn’t the gravity continue to effect the block after the initial fall when it’s loaded?