1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Prevent Creating Object Instance if a wall is above the Character?

Discussion in 'Programming' started by ChrisMG12, Jan 6, 2018.

  1. ChrisMG12

    ChrisMG12 Guest

    Hello I'm a newbie developer, who knows a little coding. So here is my situation, so i have a projectile that pushes my character every time he jumps, but i only want this projectile to appear if there is space above me, and i want nothing to appear when i'm jumping towards a wall before completing a jump.
    the code for jump projectile is in key press up and is:

    if (place_meeting(x, y+1, obj_wall))
    {
    instance_create(x,y+29,obj_jumpprojectile)
    }

    So it appears every time I'm jumping off the platform(which is the wall in this case), but i want the projectile to not appear when I'm jumping and there is a wall above me.

    If anyone is wondering i also have a obj_nothing for this situation.

    If it helps the character movement and jumping code is from this video,



    I changed the variables grav(to 1.5) and jumpspeed (to 20) .

    Thanks. Any Sort of help is appreciated.
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,262
    there might be a 1pixel space between your player's head and the ceiling. How big are your collision objects? You may want to check further up.
     
  3. ChrisMG12

    ChrisMG12 Guest

    the collision object is 64x64.
     
  4. ChrisMG12

    ChrisMG12 Guest

    should i add somrthing like

    if (place_meeting(x, y-64, obj_wall))
    {
    instance_create(x,y,obj_nothing)
    }

    would this work?
     
  5. ChrisMG12

    ChrisMG12 Guest

    yes guys i got it, it's something like this:
    if (place_meeting(x, y-64, obj_walL))
    {
    instance_deactivate_object(obj_jumpprojectile)
    }


    It took me some checking command to figure out but thanks for the help Simon Gust for helping me figure out to keep -64.
     
  6. ChrisMG12

    ChrisMG12 Guest

    so if basically if anyone wants to deactivate an object when they jump to another object from below, the code is
    if (place_meeting(x, y-HEIGHT OF THE OBJECT YOU ARE HITTING,OBJECT YOU ARE HITTING ))
    {
    instance_deactivate_object(OBJECT YOU WANT TO GET RID OF WHEN YOU JUMP INTO THE OTHER OBJECT)
    }
    Hope this has helped anyone out
     

Share This Page