Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update velocity when moving if available #395

Closed
wants to merge 4 commits into from

Conversation

dragoncoder047
Copy link
Contributor

I was trying to write some code that used the player's velocity to make footstep noises when the player moves, but the pos component's move function just updates the position, not the velocity. I had some horribly ugly hacks in place to get it working.

Why not add the move()'s "simulated velocity" to the real velocity to make it work instead? Then you can check the velocity to get the the actual motion of the object.

(I will test this and close the PR if it obviously doesn't work.)

Copy link

pkg-pr-new bot commented Sep 5, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/kaplayjs/kaplay@395

commit: 9ba6e16

@dragoncoder047
Copy link
Contributor Author

dragoncoder047 commented Sep 5, 2024

OK, that's very weird. I tried it and it COMPLETELY breaks movement; and additionally all of the fixed bodies fail to render at all (Why?)

@imaginarny
Copy link
Contributor

Shouldn't you then just use the addForce() or applyImpulse() available on BodyComp for movement?

@dragoncoder047
Copy link
Contributor Author

Shouldn't you then just use the addForce() or applyImpulse() available on BodyComp for movement?

It's not exactly equivalent, since if I use move() the body stops moving instantly when I stop calling move(), but the if I use addForce(), it will continue to slide until it hits something or slows down enough.

@imaginarny
Copy link
Contributor

Would it be possible to reset the velocity in that case to stop?

@mflerackers
Copy link
Member

Shouldn't you then just use the addForce() or applyImpulse() available on BodyComp for movement?

It's not exactly equivalent, since if I use move() the body stops moving instantly when I stop calling move(), but the if I use addForce(), it will continue to slide until it hits something or slows down enough.

You need to take into account the current velocity when calculating your force. Like the surface effector does for example.

@mflerackers
Copy link
Member

BTW, the vector rejection of a vector on the same vector is 0 because there is no orthogonal component.

@dragoncoder047 dragoncoder047 deleted the patch-1 branch September 19, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants