how do i do that?
You can select an entity and use the inspector panel in the editor to add a script component.
From there you can click and find your jump.js script and add it to your entity.
https://developer.playcanvas.com/en/user-manual/designer/inspector/
could you send a screenshot of what im looking for
- Select an entity and to the right click Add Component and add a script component.
- Then click on the empty input field that appeared together with the script component and find your jump script:
Try increasing the impulse value to something bigger, like 100 or 1000, the body has a big mass.
If that doesn’t work, try posting a sample project to take a look why it doesn’t work for you.
https://playcanvas.com/project/770644/overview/my-project-copy
That was a copy of what I did. I did everything that u told the other person to do but it’s not working for me. Please help as this is the first game that I am creating. Thanks!
That’s weird maybe try again right now. Any time I click the file it shows the code?
It should work now I think I forgot to copy the code or something
Hey @Gameinator, you had missed a few braces while copying the code, and the force value was too low due to the mass of your character. I’ve forked your project and fixed both - https://playcanvas.com/editor/scene/1102837. My suggestion would be to initially write the code by hand, and not simply copy paste in the beginning, since that’ll help you learn the PlayCanvas scripting system a bit better. Do go through the following tutorials, they’ll help you learn the engine -
Good luck with your game!
I was trying to code in my game and I noticed that the “bean” was double jumping is there a way to fix that
Hi @Gameinator, all you’ll need to do for that is limit the Y-axis movement like so -
if(this.app.keyboard.wasPressed(pc.KEY_SPACE) === true){
if (this.entity.getLocalPosition().y < //insert correct max y limit here) {
this.entity.rigidbody.applyImpulse(0, 5, 0);
}
}
Essentially, what we’re doing here is limiting how high the capsule can jump, and therefore stopping the double jump from happening.
how does this work? ive tried putting the y level in the () things, replacing the y with my chosen y level, tried putting it as y.1500 (my chosen y level) tried putting it before the < thing but nothing works it always has some issue
Hi All,
Here are the settings I have used in my first person game. First the code I put into the fps-controller script.
if (app.keyboard.wasPressed(pc.KEY_SPACE)) {
console.log("Got to Jump");
this.entity.rigidbody.applyImpulse(0,1000,0);
}
Settings for rigid body
and don’t forget to make this change to gravity in
Make sure you import Ammo
ty ima try this
i like how it feels, but i still have a infinite jumping thing, do you know how to fix it?
Can you give me a little more description? So is it that you hit the spacebar once and it keeps jumping? Do you have a public project you would be able to share?
no the issue is if you hit space while in air i can jump infinitly, also i do, ill send link
https://playcanvas.com/editor/scene/1480292