Skip to content

Trigger function just once after Collision #72

Answered by codynova
Franckapik asked this question in General
Discussion options

You must be logged in to vote
const { currentId, set } = useStore()
const hasCollided = useRef(false)
const addScore = () => {
    hasCollided.current = true
    set(state => state.playersList[currentId].score += 1)
}
const [ref] = useBox(() => ({
    mass: 1,
    args: [ 0.1, 0.1, 0.1 ],
    onCollide: e => !hasCollided.current && addScore(),
}))

Will that do the trick for you?

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by codynova
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #72 on June 17, 2020 20:07.