how to do jump a player with translate local ,i am giving translate local vec y pos +0.5, but after i want player come down to ground how?
You could do it with the physics engine:
- Add rigidbody and collision components to an entity.
- Set collision component to a capsule.
- Set rigidbody component to have angular factor set to 0, 0, 0 to stop it falling over.
- Set rigidbody mass to 80 (human weight).
- Set rigidbody type to dynamic.
- Create a script called player-controls.js and apply to entity:
var PlayerControls = pc.createScript('playerControls');
PlayerControls.attributes.add('jumpImpulse', { type: 'number', default: 100 });
PlayerControls.prototype.initialize = function () {
};
PlayerControls.prototype.update = function (dt) {
if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
this.entity.rigidbody.applyImpulse(0, this.jumpImpulse, 0);
}
};
- Create a static rigidbody entity for the ground (with a wide and deep but thin box collision primitive).
Okay Thanks Man i will try this one, But Player body dynamic means can i able to use linear velocity ? now i am using translate local for left and right movement now dynamic means i want to change movement also… is it wright…
Sure. You can do:
var PlayerControls = pc.createScript('playerControls');
PlayerControls.attributes.add('jumpImpulse', { type: 'number', default: 100 });
PlayerControls.prototype.initialize = function () {
this.velocity = new pc.Vec3(0, 0, 1); // You'd have to experiment with good values here
};
PlayerControls.prototype.update = function (dt) {
this.entity.rigidybody.linearVelocity = this.velocity;
if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
this.entity.rigidbody.applyImpulse(0, this.jumpImpulse, 0);
}
};
Thank you , i will try this one @ Will