Collision With Non-Physics Objects

I wanted to make an object such that, when it collides with another physics object, it explodes. What I found is that while physics objects can easily phase through objects that don’t have physics enabled, the CoBlock “when [object] collides with [anotherItem]” triggers on objects that don’t have physics enabled. I would like an option to ignore objects that don’t have physics enabled, or at least a way to check if the object we just collided with has physics toggled on.

Hi @Gregory_Osborne, from the top of my head I think this could be resolved by checking the collided object’s velocity. In the physics blocks there is a block for this and I’m pretty sure this will read 0 if physics is turned off (Edit: It actually returns nothing at all), and if it is a physics item, the item that collides will bump it making its velocity go up.
This can be phrased as:

When -Item- collides with “another item”
If velocity of “another item” > 0
Rest of code

(Edit, I opted to check: If velocity of “another item” does not equal “null” instead, this so that even if the object that’s been hit does not move- yet has physics enabled, it will still trigger the event.)

[Edit]
It seems to work see example;

Hope to have helped, good luck!

1 Like

It even works on colliding with static objects! Not sure how a static object has a velocity other than 0, that feels a little unintuitive, but I suppose if it works, it works. I tried to debug the velocity of the static object with a title, included as a photo here, but I suspect there’s some rounding going on, and the static object has really small velocity? Thanks for your help.

While I’m mentioning debugging the velocity, any chance we could get some kind of Console log in CoSpaces using the blocks? I’m finding it difficult to output information about the program as it is running, and I’d love the ability to know what the values of variables are at a specific point in my code block. The problem with using the Title is that it pauses the code blocks but not the time or physics system, so all the stuff that would happen on the collision only happens when I close out of the Title, after the ball has bounced away.

DebugVelocityCodeBlock

@Gregory_Osborne If you dont want static objects to trigger it then go into the “data” blocks and grab the “x/y/z of” block and use the x cooirdinate of world velocity of another item > 0 to check.
As you saw when printing this value it is actually a vector (consisting of 3 values) so this cannot be directly checked to a single value. If you want to get very precise with it you could add up the x,y and z and check if that is still 0 (and if any rounding errors occur use the round to x decimals block)

But yes I do second having a debug menu/ console; In fact I did see a block like that in the marble maze game from coSpaces themselves but it seems they have removed the function of it. Usually what I do is i have a character / object say the value I want to know in order to debug.

Hope the game is coming along, good luck!

1 Like