Knock Back not working

huenix

Member
Hello....

I have looked all over the forum, and others issues are not the same and/or use different codes...
When ever a AI/Player is knocked back, this code is called
it will work and prevent the AI/Player from passing through the "obj_character" OR "blocked_by" but never BOTH, now matter how i do it. and only when it is one or the other.

I have tried : | ...|| ...& ...&& ... (C) || (B) ... even and else if statement
What am i missing? šŸ˜­




var blocked_by;

if (through_walls) && (over_pits = false) //ONLY walks through walls, NOT over pits
{
blocked_by = obj_pit;
}

if (through_walls = false) && (over_pits) //NOT walks through walls, Only over pits
{
blocked_by = obj_wall;
}

if (through_walls = false) && (over_pits = false) //NOT walks through walls, OR over pits
{
blocked_by = obj_solid;
}

if (through_walls) && (over_pits) //Walks through walls AND over pits
{
blocked_by = noone;
}

//Where AI is knocked to
if (knockedback)
{
if (place_meeting(x + knockedback_x, y + knockedback_y, obj_characters || blocked_by))
{
x += knockedback_x;
y += knockedback_y;
}
knockedback = false;
}
 
IT all needs to be inside the same IF statement brackets.

Your using && like this:
GML:
if (through_walls) && (over_pits = false)
It needs to be like this
GML:
if (through_walls && over_pits = false)
Also, I don't think you can use OR like this:
GML:
if (place_meeting(x + knockedback_x, y + knockedback_y, obj_characters || blocked_by))
I think it has to be like this:
GML:
if (place_meeting(x + knockedback_x, y + knockedback_y, obj_characters) ||
    place_meeting(x + knockedback_x, y + knockedback_y, blocked_by))
 
Top