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

C

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.
 

Simon Gust

Member
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.
 
C

ChrisMG12

Guest
should i add somrthing like

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

would this work?
 
C

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.
 
C

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
 
Top