Forum

> > CS2D > Scripts > Projectile 'wall' collision
Forums overviewCS2D overview Scripts overviewLog in to reply

English Projectile 'wall' collision

5 replies
To the start Previous 1 Next To the start

old Projectile 'wall' collision

KenVo
User Off Offline

Quote
I finally got my own projectile script to work. However, I can't make it so that the projectile get removed whenever it touches a wall. I tried something like this and it wouldn't work.

1
2
3
4
if tile(self.x,self.y,"wall") == true then
		--Wall collision
		self:destroy(id)
	end

This works for player:
1
2
3
4
5
6
7
8
9
for i,v in ipairs(player(0,"table")) do
		--Player collision
		if(i ~= self.pid) then
			if(self:collision(i)) then
				EXPhit(i,id,256,self.dmg)
				self:destroy(id)
			end
		end
	end

old Re: Projectile 'wall' collision

EngiN33R
Moderator Off Offline

Quote
You won't get a tile parameter if you supply coordinates in pixels. It should be
1
math.floor(self.x/32)
And the same for y, too.

old Re: Projectile 'wall' collision

Apache uwu
User Off Offline

Quote
Asserts for the win:

1
2
3
4
5
6
7
_tile=tile
function tile(x,y,value)
	assert(x<map("xsize"),"bad argument #1 to 'tile' (exceeds map size)")
	assert(y<map("ysize"),"bad argument #2 to 'tile' (exceeds map size)")
	assert(_tile(x,y,value),"bad argument #3 to 'tile' (undefined value)")
	return _tile(x,y,value)
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview