Destroy instance with right_mb

J

jason

Guest
I am using a controller object with a step event that allows a users to create a selected physics fixture with the left mouse button. I would like to add a delete mode or have the right mouse button delete a fixture that is clicked on. I have tried several ways and have been able to make all instances destroy, but can't seem to have just the instance that is clicked on destroyed.

I'm currently trying with instance_place and have tried with place_meeting, but have been unable to accomplish this.

Any advice would be greatly appreciated.


var hit;
hit = instance_place(mouse_x, mouse_y, obj_base);
if (mouse_check_button(mb_right)) && (hit != noone)
{
with (hit) instance_destroy();
{
instance_destroy();
}
}
 
B

Braffolk

Guest
You should use instance_position instead. instance_place checks for collision between the object that ran the code and the specified object.

Edit: Also, What's going on with the double instance_destroy() and parentheses everywhere? pretty sure that would also destroy the controller object.

Try something like this:
Code:
var hit;
hit = instance_position(mouse_x, mouse_y, obj_base);
if (mouse_check_button(mb_right) && hit != noone)
{
    with (hit)
    {
        instance_destroy();
    }
}
 
Last edited by a moderator:
J

jason

Guest
Braffolk,

Thank for your reply. I have switched over to the instance_position and it tested it with a test instance of another object and it will destroy that object. However it will not destroy the instance of the physics fixture.

Here is the code I am using to create and attempt to destroy.



Destroy code

if mouse_check_button(mb_right){
var hit;
hit = instance_position(mouse_x, mouse_y, obj_base);
if hit != noone
{
with (hit) instance_destroy();
}
}

Create Code

if ((alarm[0] < 0) && (global.build == 2))
{
var instA = instance_create(mouse_x, mouse_y, obj_base)
var fixA = physics_fixture_create()
physics_fixture_set_box_shape(fixA, 25, 25);
physics_fixture_set_density(fixA, 0.9);
physics_fixture_set_restitution(fixA, 0.7);
physics_fixture_bind(fixA, instA);
physics_fixture_delete(fixA);
alarm[0] =5;
}
 
W

Wintery

Guest
Being as each physics_fixture has it's own id, I would say have the objects they are connected to also store the id of that physics_fixture. Then make it part of the objects destruction to remotely call the destruction of the linked physics_fixtures.
 
J

jason

Guest
Adding a sprite to this object allowed this to work as I would expect.

Thanks,
 
Top