Forum

> > CS2D > Scripts > Player Collision
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Player Collision

12 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Re: Player Collision

DannyDeth
User Off Offline

Zitieren
Simply check the distance between the two players, if it is less than approximately 28 pixels a collision has occurred.

alt Re: Player Collision

DC
Admin Off Offline

Zitieren
The player collision size is 12 pixels around the center on the x and y axis. Not a circle, just a square. This makes things even easier.

So it works this way (just using cs2d lua cmd 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
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 cs2d cmd 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.

alt Re: Player Collision

DC
Admin Off Offline

Zitieren
It simply fits best. The player skin is 32x32 pixels, so 16 pixels around the center would make most sense at first glance. But not all the 32x32 pixels are filled. So 4 are subtracted on each side to make it fit better. This also allows you to go quite easily through narrow passages which have a size of just 1 tile (which is 32x32 too). Imagine the player collision would be 32x32 as well. It would be quite difficult to navigate the player through such narrow passages. This would be quite annoying and unplayable

alt Re: Player Collision

Avo
User Off Offline

Zitieren
Ok, I'm just interesting. So player's collision area is square, not circle?

alt Re: Player Collision

DC
Admin Off Offline

Zitieren
Please read what I wrote before asking... I already explained it
user DC hat geschrieben
[...]Not a circle, just a square[...]

alt Re: Player Collision

Apache uwu
User Off Offline

Zitieren
Player hit detection is indeed a square, but for hit detection, since the player's image is more so like a circle, we should really use the distance formula.

alt Re: Player Collision

Apache uwu
User Off Offline

Zitieren
That's for bullet hit detection. The image of the ct/t is close to being a circle than a square.

If 2 players were to hit diagonally, they would stop short from colliding--looking unrealistic.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht