GMS 2 switch fixture between sensor and non sensor

Discussion in 'Programming' started by zim32, Dec 4, 2018.

  1. zim32

    zim32 Member

    Joined:
    May 23, 2018
    Posts:
    68
    I am trying to switch between sensor and non sensor since simply using fixture_set_sensor again didn't seem to work I tried removing and delete the first fixture and creating a new one but that didn't work either

    step event
    Code:
    if(global.powerball=true){
    physics_remove_fixture(obj_ball,fix_ball)
    physics_fixture_delete(fix_ball)
    fix_ball2=physics_fixture_create()
    physics_fixture_set_circle_shape(fix_ball2, sprite_get_width(spr_ball) / 2);
    physics_fixture_set_sensor(fix_ball2, true)
    physics_fixture_set_collision_group(fix_ball2,-1)
    physics_fixture_set_density(fix_ball2,.5)
    physics_fixture_bind(fix_ball2,obj_ball)
    global.powerball=false
    fix=fix*-1
    }
    
    create event
    Code:
    fix_ball=physics_fixture_create()
    physics_fixture_set_circle_shape(fix_ball, sprite_get_width(spr_ball) / 2);
    physics_fixture_set_sensor(fix_ball, false)
    physics_fixture_set_collision_group(fix_ball,-1)
    physics_fixture_set_density(fix_ball,.5)
    physics_fixture_bind(fix_ball,obj_ball)
    
     
  2. zim32

    zim32 Member

    Joined:
    May 23, 2018
    Posts:
    68
    did ask the question in a stupid way ? what about an alternative method? What I am trying to do is make one of those power ups you get in brick breaker games that allows the ball to just plow through the bricks instead of bouncing off as it destroys the brick and then it wears off after a certain amount of time anyone know a good way to do that
     
  3. Jezla

    Jezla Member

    Joined:
    Jun 20, 2016
    Posts:
    407
    You're on the right track by trying to remove one fixture and replace it with another, but you need to review the manual section on binding fixtures. You are trying to remove the fixture that defines the properties, not the fixture that is actually bound to the object.

    Code:
    //Setting up the fixture
    fix = physics_fixture_create();
    
    //Define fixture properties
    
    myfix = physics_fixture_bind(fix, id); //Store the bound fixture ID in a variable
    
    physics_fixture_delete(fix);  //Delete the 'template' fixture to prevent memory leaks
    
    //Change the fixture
    physics_remove_fixture(id, myfix);
    
    //Define and bind the new fixture the same way you did the old one.
    
    Note how I save the ID of the bound fixture in a variable so it can be referred to later? That's what you should use when you remove the fixture.
     
  4. zim32

    zim32 Member

    Joined:
    May 23, 2018
    Posts:
    68
    okay it works thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice