1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Changing instance on collision (SOLVED)

Discussion in 'Programming' started by YetAnotherGameDev, Aug 3, 2019.

Tags:
  1. YetAnotherGameDev

    YetAnotherGameDev Member

    Joined:
    Aug 3, 2019
    Posts:
    4
    I want to make my player object change the colour of the ground when the player collides with it. I've put this code in my step event for the ground (for reference, the object is called obj_ground_1_normal):
    if(place_meeting(x, y, obj_player_red))
    {
    instance_change(obj_ground_1_red, false);
    }

    Sometimes it works, sometimes it doesn't, and I don't know why. Please help.
     
    Last edited: Aug 3, 2019
  2. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    422
    I feel like this effect would be better accomplished by changing the sprite_index of the object, and not the type of object (object_index.)
     
  3. YetAnotherGameDev

    YetAnotherGameDev Member

    Joined:
    Aug 3, 2019
    Posts:
    4
    It still only works occasionally.
     
  4. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    441
    edit
     
  5. Old School Ben

    Old School Ben Member

    Joined:
    Feb 28, 2018
    Posts:
    18
    I agree with YoSniper. You might just want to change the sprite.

    You may need to destroy an object while simultaneously creating one at the same x and y location.

    Really depends on what you are trying to accomplish.
     
  6. YetAnotherGameDev

    YetAnotherGameDev Member

    Joined:
    Aug 3, 2019
    Posts:
    4
    I tried both of those things (both via code and "drag and drop" commands) and it still only works about 60% of the time. That's my problem.
     
    Last edited: Aug 4, 2019
  7. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    424
    Probably just an oddball collision issue with the mask or moving too fast. Especially the concept is you are changing the floor color here I would use distance_to_object and check if you are closer that the speed you are traveling.
     
  8. YetAnotherGameDev

    YetAnotherGameDev Member

    Joined:
    Aug 3, 2019
    Posts:
    4
    I tried distance_to_object and it works every time now. Thank you!
     

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