I have a drone gun, and I want to destroy it in 5 hits. I have a property set to equal 5, and remove visibility of it, however how can I add hits each time a bullet touches it?
Meaning if 3 bullets hit it, it has a property of 3, and when it gets to 5, it turns invisible (blown up)
If the ship there collides with an object with the ‘bullet’ property (Collision sensor with And controller), then add 1 to the ‘hits’ property (Actuator). That should be it.
If you’re using dynamic objects for bullets, set a “Collision” sensor detecting a “bullet” property, an and controller, and a “Property” Actuator that “adds” 1 to the Hits property. If you’re using static objects, use a “near” sensor doing the same thing.
Didn’t make much progress, added the things I thought would work, but after like 20 shots, nothing happens. The gun turret you see in the picture, that needs to go away when hit by a bullet.
Is the bullet traveling at a set velocity, or is it using a force? If it’s a set velocity, it won’t recognize the collision. Try using a near sensor that’s adjusted to fit it’s bounding box.
Also, make sure the property’s an integer, I’ve forgotten this step often.
Edit: Actually, from your screenshot, it appears you haven’t added the hits property to it. I don’t see the property box under the “add property” button.
First off, the bullet is a static object. Use a “Near” sensor to detect it, using Loc will not register a collision.
Secondly, select the drone and press the “Add Property” button. Name it “hits”. Change it to an integer by clicking the button that says “Float” and select “Int” This should resolve your issues.
Just like how you had to add a property named “hits” to the drone, you must add a property named “bullet” to the bullet object. That’s the property the near sensor is looking for.