Forum
CS2D Scripts Player CollisionPlayer Collision
12 replies 1
So it works this way (just using player, very basic math and math.abs which make all values positive = removes the minus if there is one)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
function playerscollide(id1,id2) 	x1=player(id1,"x") 	y1=player(id1,"y") 	x2=player(id2,"x") 	y2=player(id2,"y") 	if (math.abs(x1-x2)<12) and (math.abs(y1-y2)<12) then 		return true -- players id1 and id2 collide 	else 		return false -- players id1 and id2 don't collide 	end end
well.. this is the way to DETECT collisions. Making players actually collide (you would have to use setpos in case of a collision) is a bad idea because the Lua code is executed on the server only so this will become very laggy und jerky when you try it in a net game. Also lag and high pings might allow players to "lag" through each other without collision. You would have to use a rather complex code to avoid this stuff.
DC has written
[...]Not a circle, just a square[...]
If 2 players were to hit diagonally, they would stop short from colliding--looking unrealistic.
1