danzen / zimjs

ZIM JavaScript Canvas Framework - Code Creativity! Interactive Media For All.
Other
507 stars 47 forks source link

ball movement with connected physics #54

Closed romaniom closed 11 months ago

romaniom commented 1 year ago

hello! I have connected box2d in my project, I need the ball to move at the touch of a button. But nothing works, I've tried a lot of ways, with physics connected, nothing works except impulse and keyboard movement. But I need the ball to move when the button is pressed. Animation doesn't work either.

danzen commented 11 months ago

Sorry - missed this until now! You can get us faster at https://zimjs.com/discord or https://zimjs.com/slack. Physics objects are supposed to be controlled by forces. So you want to apply an impulse(x,y) when you press the button.

const button = new Button().center()
button.on("mousedown", ()=>{obj.impulse(100,0);});

will shoot the object to the right for instance.