Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

add jumpRelease function to BodyComp#781

Closed
joshuacurtiss wants to merge 1 commit into
replit:masterfrom
joshuacurtiss:joshuacurtiss/jump-release
Closed

add jumpRelease function to BodyComp#781
joshuacurtiss wants to merge 1 commit into
replit:masterfrom
joshuacurtiss:joshuacurtiss/jump-release

Conversation

@joshuacurtiss

Copy link
Copy Markdown

Problem: When jumping with the jump function in BodyComp, a force is applied but thereafter you can't change the velocity. What about if you want to: (a) Change the height of jump based on how long the player holds down the jump key? (b) Want to stomp down in the middle of a jump?

Solution: With this function, you can accomplish the points mentioned above with a jumpRelease function that lets you change the velocity mid-jump.

Example of use can be seen here:
https://www.curtiss.me/build-mario-with-kaboom/

(Notice how short or long jumps can be achieved by how long you hold the jump button, or stomping down by pressing down mid-jump)

How it is accomplished in the sample:

Thanks for your consideration.

@slmjkdbtl

Copy link
Copy Markdown
Contributor

What do you think about just expose vel? This should enable most things

@slmjkdbtl

Copy link
Copy Markdown
Contributor

So you can just

// Accelerate falling when player holding down arrow key
onKeyDown("down", () => {
	if (!player.isGrounded()) {
		player.vel.y += dt() * 1200
	}
})

// Jump higher if space is held
onKeyDown("space", () => {
	if (!player.isGrounded() && player.vel.y < 0) {
		player.vel.y -= dt() * 600
	}
})

@joshuacurtiss

Copy link
Copy Markdown
Author

Hi @slmjkdbtl! Yes, exposing vel would make me happy and would be more versatile. 🎉

@slmjkdbtl

Copy link
Copy Markdown
Contributor

vel is exposed in v3000.1.17!

@slmjkdbtl slmjkdbtl closed this Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants