What is the method for getting my character to jump in Phaser 3?

I'm a beginner in Phaser 3 and I'm facing an issue with my character's jumping mechanic.

Here is the code snippet I'm currently using:

create() {
    this.player = this.physics.add.sprite(50, 380, 'idle');
    this.player.setScale(.3);
    this.player.setGravityY(300);
    this.player.setBounce(0.2);
    this.player.setCollideWorldBounds(true);
    this.physics.add.collider(this.player, this.platforms);
    this.cursorKeys = this.input.keyboard.createCursorKeys()
}

update() {
    this.movePlayer()
}

movePlayer() {
    if (this.cursorKeys.left.isDown) {
        this.player.setVelocityX(-300)
    } else if (this.cursorKeys.right.isDown) {
        this.player.setVelocityX(300)
    } else {
        this.player.setVelocityX(0);
        this.player.setVelocityY(0);
    }
    if (this.cursorKeys.up.isDown && this.player.body.touching.down) {
        this.player.setVelocityY(-300);
    }
}

Currently, my character only jumps a few pixels up and then stops. If I remove the touching.down condition, the player can jump freely but the jump feels slow and floaty regardless of the gravity settings.

Any suggestions or solutions to improve the jumping behavior would be greatly appreciated!

Answer №1

In order to improve the character's fall speed, consider removing the line of code that sets the y velocity to zero when there is no keyboard input. This constantly halting the character's motion during each game update cycle results in a slower descent.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How is the server architecture typically designed in a node.js application?

Currently, I am developing a node.js application using socket.io and I'm seeking advice on how to structure the folders properly. The files that I have in my project include: Server.js package.json Additionally, I have: Client.js Index.html Incl ...

The Material-ui Drawer does not function properly when used with an external CSS file

For my project, I'm working on a Sidebar design that is inspired by the Mini Variant drawer demo available at this link. However, the project requirements mandate that all CSS styling should be done in a separate CSS file rather than directly within t ...

Include a link in the email body without displaying the URL

My concern revolves around displaying a shortened text instead of the full link within an email. When the recipient clicks on "Open Link," they should be redirected to the URL specified. The text "Open Link" must appear in bold. My current development fram ...

Is there a way to add a child to a div with a randomly generated id number?

Don't miss the update at the end! :) I'm developing a small website where users can input data into multiple text boxes, and when they return later, their information is still there (essentially a basic helpdesk system using local storage). The ...

Submit JSON data that is not empty in the form of a custom format within the query string

Attempting to transmit JSON data using a GET request. JSON data: var data = { country: { name: "name", code: 1 }, department: {}, cars: ["bmw", "ferrari"], books: [] } Code for sending: var posting = $.ajax({ ur ...

A dynamic jQuery plugin for creating captivating image slideshows

I am in need of a recommendation for a jQuery carousel plugin that has the capability to create a carousel similar to the one shown in the image. Specifically, I am looking for a carousel where the active image item moves to the center and becomes larger. ...

``Are you looking to unlock the power of vertex and fragment shaders within your three.js projects

Recently, I delved into the world of WebGL by starting to work through a book titled "WebGL: Up and Running". This book utilizes my preferred rendering solution, THREE.js, for creating 3D objects in web browsers. One section of the book caught my attention ...

Sending an array as a query string

I am trying to send an array to my server using jsonp. Here is an example of the JSON I want to pass: ["something","another_thing",4,{"iam" : "anobject"}] However, I am unsure about how to actually pass an array. I thought it might work like this: some ...

Purging the items from the listview

I am currently facing an issue with my code, where the listview contents are stacking up instead of being cleared and updated every time I press the button. I want the previous listview contents to be cleared each time I update the stored array contents an ...

How to send a JavaScript variable to Flask and trigger an AJAX reload action

Introduction: I have explored similar inquiries and attempted to apply relevant code/concepts but without success. -https://stackoverflow.com/questions/43645790/passing-javascript-variable-to-python-flask -https://stackoverflow.com/questions/10313001/is- ...

Unable to choose radio button again

Check out this fun web quiz I created! I'm having some trouble with the back button functionality. Whenever a user clicks back, I want to restore their previous choice but for some reason it's not working as expected. Take a look at my go_back ...

Exploring the World of Node.js Background Operations

What is the best approach for handling background processes in a NodeJS application? Situation: When a user posts something to an app, I need to process data, fetch additional information from external sources, etc. Due to the time-consuming nature of the ...

Is it possible to modify @page directive(CSS) values from the code-behind(C#) or JavaScript?

Using the @page directive, you can define the printer margins for a page separately from regular CSS margins: <style type="text/css" media="print"> @page { size: auto; /* auto is the current printer page size */ margin ...

Transferring time between functions in Vue.js: A journey from one function to another

Struggling to pass the value from checkMp3SizeAndDuration method function to data() {return { time: '' } } Check out the code snippet below: data () { return { time: '' } }, methods: { checkMp3SizeAndDuration ...

Can I incorporate the name of my web application into the URL using Node.js?

Is it possible to include my web app name in the URL using Node.js? Currently, my web app runs on I am looking to have the pathname /myapp added like so: ...

Initial Year Setting for MUI X datepicker

For a project I am working on with my client, they have requested that the datepicker in MUI X default to the year 2023. They would like the datepicker to automatically display the year 2023 with the option for them to change it if needed, as most of the d ...

Setting a default blank value in Select2 multiple mode

I have a dynamic multiple choice input that utilizes the Select2 plugin. I want to include a "blank" option with an empty value and a title to give the appearance of nothing being selected, but indicate to the user that an option is indeed chosen as "All." ...

Regular Expression designed specifically for detecting alternative clicks

When using ngpattern for validation, I have encountered an issue where my error message is displaying for a different reason than intended. The error message should only show if the field is empty or contains only special characters. <textarea name="ti ...

Presentation: Troubleshooting Ineffective CSS3 Transitions

I have created a basic slideshow that can accommodate multiple images. Clicking on an image should move to the next slide, and once the last image is clicked, it should loop back to the first slide. The functionality of transitioning between slides seems ...

Display when moving up and conceal when moving down

Is there a way to make the div appear when scrolling up and down on the page? I'm new to jquery and could use some assistance, please. ...