Horizontal Projectile Help

I've been trying for a while and I can't seem to make this sort of projectile that shoots to the left or right, (Depending on where the player is facing) and continues moving in that direction until hitting a wall. I feel like this should be sort of easy, but I just can't seem to figure out how to get the tile to keep moving! Can anybody give me any suggestions?

I ran into this problem a while ago, and here's how I fixed it.

Starting off, you want to know the direction the player is facing, which can be done with event.dx and event.dy (I used frames for the different directions the player can face).

Next you want to lock in the direction of the bullet when shooting, so I use a different variable to store your current facing direction once you shoot.

Moving the bullet is as simple as adding or subtracting to the X or Y of the bullet according to the direction now.

And finally, I don't use a tile at all, but the draw function and some checks for hitting something solid. When it does hit, the bullet stops moving, stops drawing, and calls the function "shot" on whatever it hits.

Here's the full code.
on update do
	if event.dx==-1 then
		player_facing_dir = 2
		frame player_facing_dir
	elseif event.dx==1 then
		player_facing_dir = 3
		frame player_facing_dir
	end
	if event.dy==-1 then
		player_facing_dir = 0
		frame player_facing_dir
	elseif event.dy==1 then
		player_facing_dir = 1
		frame player_facing_dir
	end
end

on confirm do
	
	if player_bullet_traveling==0 then
		
		player_bullet_x = event.px
		player_bullet_y = event.py
		
		player_bullet_traveling = 1
		player_bullet_dir = player_facing_dir
		
		if player_facing_dir==0 then
			player_bullet_y -= 1
		elseif player_facing_dir==1 then
			player_bullet_y += 1
		elseif player_facing_dir==2 then
			player_bullet_x -= 1
		elseif player_facing_dir==3 then
			player_bullet_x += 1
			
		end
	end
end

on any do
	if player_bullet_traveling==1 then
		
		if player_bullet_dir==0 then
			player_bullet_y -= 1
		elseif player_bullet_dir==1 then
			player_bullet_y += 1
		elseif player_bullet_dir==2 then
			player_bullet_x -= 1
		elseif player_bullet_dir==3 then
			player_bullet_x += 1
			
		end
		if player_bullet_traveling==1 then
			player_bullet_solid = solid player_bullet_x,player_bullet_y
			if player_bullet_solid==1 then
				player_bullet_traveling = 0
				tell player_bullet_x,player_bullet_y to
					call "shot"
				end
			end
		end
	end
	
end

on draw do
	if player_bullet_traveling==1 then
		draw "bullet" at player_bullet_x,player_bullet_y
	end
end
2 Likes