Can someone check my setup for physics collisions? I want to put in the gallery

Hi everyone,
Does someone have a chance to see if this works for me? I set up a space that I want to share in the gallery for collisions of vehicles of different masses. I am new to coding and just want to see if what I did makes sense. I wish I could copy and paste my code easily but here’s some of it:


Hi @Jennifer_Cauthers,

you can easily share the space with us by pressing the ‘Share’ button in the toolbox (unlisted, so that it is not visible in the gallery yet). We then can take a look at and its code it so see what can be improved :slight_smile:

Sounds good. Thanks! Here it is:

I think the proof is in the testing, @Jennifer_Cauthers - works well!

Thanks!! Just didn’tn’t know if my code was inefficient.

Hi @Jennifer_Cauthers,

The space you shared is a very interesting physics sandbox! Here’s some feedback on your code:

  1. You place event handler blocks (when car is clicked, when truck is clicked, etc.) into a run separately block. Please note that these kind of blocks will set up behaviour that will happen at some time during the play mode, so there is no need to add them in separate code execution with the run separately - block.
    Since your entire space is event handler - based, you can safely place all event blocks after each other.

  2. The reset button is very useful! However, after you reset the vehicles, you can not apply more velocity on the items by pressing the ‘test’ button anymore. This is because the items are still static after the reset. To fix this, simply set their static to off after you’re done resetting their position.

I’m working on a more in-depth tutorial about using physics with CoBlocks to make you aware of some unique behaviour about physics items :slight_smile:. For now, please note that static physics items can be moved like regular items, and be collided against by other non-static physics items, but can not be given velocity themselves.

I’ve send you a private message with a version of your space that has improvement suggestions.

Hope this helps!

Hi Stefan,
Thanks so much for giving such detailed feedback.

I wasn’t sure about the event handler so played it safe with the run separate. Thanks for the clarification.

The part I had the most trouble with was the reset. I could easily get the vehicles back to start and even momentarily stopped. But then they started rolling. I tried turning physics off and then back on but they still rolled… Should I have set a pause before turning physics back on? Maybe they never came to a complete stop? The only thing that worked was making them static.

That was my biggest challenge. Other than that the space was fun to build and shows collision with different masses pretty well in simulation.

Thanks so much for your help! I’ve got a bunch to learn but love it.

1 Like

Hi @Jennifer_Cauthers,

thanks to your space we noticed an odd behaviour regarding switching physics items on static and off again. I’ve reported this issue to our developers. There are many ways to reset the velocity of a physics-enabled item, one would have been to switch static on, move the item, then switch static off again. Right now, it sadly does only work when you include a pause block between, as demonstrated in the space I’ve shared with you.

Another way would be to use the physics blocks from the Physics->Advanced category:

  1. Use the set physics position - block to move the item to its reset position
  2. Use the set velocity - block to reset the item velocity

This way you don’t need to switch the item’s static property on or off.

I’ve added another example to the space I’ve linked to you. If you visit the link and remix the space, you’ll get a new version with two scenes in it. The second scene uses the example explained above :slight_smile:

Thanks Stefan! I did try to turn physics off then back on and that didn’t work either but I didn’t try a pause.

Again thank you so much for all of your help!

1 Like