• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Throwing knife in wall

D

Distorted

Guest
so this might be a bit specific but I'm working on a game that involves throwing knifes.

once a knife is in the wall the speed goes to 0 and I want it to be stuck there.

only because of the speed of the knifes most of the times they get stuck in the middle or even stick out the other side of the wall object.

I've been brainstorming on this for a couple hours now, can somebody help me?
 

Tulloch

Member
Well it seems like you're just throwing knives at the wall and hoping they stick.

Bad joke.

I would suggest sharing your code so we can see what could be causing those results.

I can suggest that you look into pixel perfect collision.
 
D

Distorted

Guest
Well it seems like you're just throwing knives at the wall and hoping they stick.

Bad joke.

I would suggest sharing your code so we can see what could be causing those results.

I can suggest that you look into pixel perfect collision.
if (place_meeting(x+1,y,obj_solid)) or collision_line(xprevious,yprevious,x,y,obj_solid.x+1,0,1)
{
move_towards_point(obj_player1.x+300,obj_player1.y,0)
x = xprevious
y = yprevious
}

if (place_meeting(x-1,y,obj_solid)) or collision_line(xprevious,yprevious,x,y,obj_solid.x-1,0,1)
{
move_towards_point(obj_player1.x+300,obj_player1.y,0)
x = xprevious
y = yprevious
}

kind of embarrassed to show this tbh
 
D

Distorted

Guest
I have no idea why but now they're all getting stuck before hitting the wall and for some reason when I shoot them trough a wall to the right it passes trough and then stops.
 

poliver

Member
you need pixel perfect collision

instead of moving knife the 'speed' amount of pixels per frame like x+ = 10

you need
Code:
repeat(knife speed amount of times)
{
        x += 1;
        if (collision with the wall)
                break; //break the loop
}
 
D

Distorted

Guest
you need pixel perfect collision

instead of moving knife the 'speed' amount of pixels per frame like x+ = 10

you need
Code:
repeat(knife speed amount of times)
{
        x += 1;
        if (collision with the wall)
                break; //break the loop
}
thanks! I believe I've already fixed the problem, but I'll keep this in mind
 
Top