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

Feature Request: Fire a mid-update event, after all body positions set, but but just before collision detection begins. #1173

Closed
OdinvonDoom opened this issue Nov 10, 2022 · 1 comment

Comments

@OdinvonDoom
Copy link

I'm just really looking for the chance to have the engine do it's basic velocity-position updating (Engine.js: Engine._bodiesUpdate), but then get to run a bit of my own code before any of the collision detection begins. Then I could make whatever minor tweaks I feel I need, like if a body slightly overshot a target destination in that frame, I could repositions them to be precise, and then there would be no chance of an incorrect detection being made.

Example: player clicks to move 25px away, and velocity has then going 10px per frame. Each frame I'd check if target pos is between prev and curr pos (20 and 30), and if so, hard-set to desired pos, and negate velocity, THEN collisions are checked, no chance of hitting some thing that was originally 28px along the path.

@liabru
Copy link
Owner

liabru commented Nov 12, 2022

I've logged this as a feature request, but in the meantime you could try something like:

Matter.after('Engine._bodiesUpdate', () => {
 // do something here
})

It's not ideal but might do the trick for some cases.

@liabru liabru closed this as completed in 8dd0e99 Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants