is there a way to when i press the key, instead of making a movement i just have the player model(bean) shrink on the Y axis and the collision model too? so that way physics takes charge and makes the player crouch.
Crouch in playcanvas
so first what you need to do is make a file by clicking the + button, and clicking script after that you will have some javascript code that looks like this
var Crouch = pc.createScript('crouch');
// initialize code called once per entity
Crouch.prototype.initialize = function() {
};
// update code called every frame
Crouch.prototype.update = function(dt) {
};
// swap method called for script hot-reloading
// inherit your script state here
// Crouch.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
now you can see the Crouch.prototype.update = function (dt) {
}
what you want to do now is this take my code copy, and paste in in to the update function here is my code
if (this.app.keyboard.isPressed(pc.KEY_C)) {
this.entity.collision.height = 1;
} else if (this.app.keyboard.wasReleased(pc.KEY_C)) {
this.entity.collision.height = 2;
}
1 Like