Randomly spawn object at different places in room.

Discussion in 'Game Design, Development And Publishing' started by Ancestralsoul, Jan 5, 2020.

  1. Ancestralsoul

    Ancestralsoul Member

    Joined:
    Dec 31, 2019
    Posts:
    30
    How would I go about doing this in game maker 2? Does crate instance not exist in game maker 2?
     
  2. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    224
    Gm2 uses instace_create_depth instead, only difference is that you pass it a depth (or, the layer alternative). If you simply want to place it randomly in a room you would just do

    Code:
    Instance_create_depth( irandom_range( 0 , room_width ) , irandom_range( 0 , room_height) , depth , object )
    But that is as basic as it comes. If you have walls and other solid objects that it should avoid spawning on you have to do checks and move stuff around, but that all depends on what you want to do exactly.

    References

    https://docs2.yoyogames.com/source/...instance_functions/instance_create_depth.html
    https://docs2.yoyogames.com/source/...instance_functions/instance_create_layer.html
    https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/maths/number functions/irandom_range.html
    https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/rooms/general/index.html
     
    Last edited: Jan 5, 2020

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