Im learning Honest ! collision object assistance please!

I been trying to get anything and everything to have a collision and fire the event and simply print the sender to know i have the collision layout info setup correctly but i am unable to to get the event to fire at this point im now not even sure which script i should be collecting from when the event happens?

Once of those done it once and never forget kinda issues eh !

Thanks for help btw…

So, if you have a game object with a collisions component it will post collision_response messages when it collides. In order for collisions to happen you need to configure your collision components in such a way that the collision component group will match the mask of another collision component. Read up on the physics engine in Defold here.

To explain a bit further I have a bullet that has a ever changing position using the update function and upon reaching the edges of the screen is deleted i cannot get this to collide. Other objects which dont use the update function collide and fire the event

Its a factory generated sprite which has a collision object in the collection just like the other objects which appear to work but this one fails to do so any ideals?

Also wondering how to collect what object has collided with which rather than just the event has happened.

Hmm, ok, just so that I understand:

The bullets are game objects with a sprite, a kinematic collision component and a script. In the update function of the bullet script you move the bullet, correct? And in the on_message function of the same script you check for collision messages but don’t get any?

And you have other game objects with collision components that collide with each other?

What happens if you go to game.project and check the physics->debug checkbox? You should with physics debug enabled see all collision components and how they collide while running your game. Maybe you could take a screenshot and share it? Maybe also take a screenshot of the bullet game object and it’s setup (outline and properties window). And the same for whatever object you want the bullets to collide with.

Ah think i have traced the issue as i did have some of the bullet code in the spaceship collection and now have a bullet collection which does not include the factory since that is still in the spaceship collection im guessing this would be the collision issue since the bullet would be within the spaceship issue and therefore not a true bullet when checking the collision if that makes sense ?

These issues all help me to learn how this engine actually works…

I think I understand what you are saying. As long as you have the script checking for collisions attached to the same game object as the collision component then it should work.

The sprite is activated upon running which i dont know how to stop yet when this moves it will collide ok but factory generated objects dont is there something im missing since the code would be the same as the script is used in all factory created objects.

So how do i stop a sprite showing on start up and is the code different when detecting collisions with factory generated objects?

You can enable/disable a sprite by sending a message to it:

msg.post("#sprite", "enable")
msg.post("#sprite", "disable")

There is no difference in the collision handling of factory generated game objects when compared to other game objects.

Please post a screenshot of the Outline and Properties windows when you have the factory created game object open and the collision component selected.

Hi Britzl,

I have amended code and have something working but when the factory spawns in physics debug mode the factory sprite does not show a collision object within the sprite any ideals anyone?

Thanks for attaching the picture. So, you have an asteroid with a collision component, a script and a sprite as shown in the picture. And the asteroid does also have a factory, what does the factory spawn? More asteroids? Or something else?

What’s the size of the Sphere shape you use as collision shape? Does it not show in debug mode?

I just found that the asteroid.go has to have the collisionobject for the factory generated sprite to contain the collisionobject so im heading in the right direction now, basically a over sight in laying out all the objects in the right places…

now in debug i have the collision object in the spawned sprite

Ok, great, so you got it working?

The key thing to remember when it comes to collisions is that if you want a game object to collide with something it needs a collision component and a script to pick up on the collision messages.

Yes got it working had the wrong things in the wrong places it now looks like the following

And the factory .go file contains everything else.

Now i can spawn and it creates with the collision object, my posts may be of use to someone who experiences the same issues so it was a nice learning curve.

Thanks for your help britzl

1 Like

Excellent! Happy coding!