Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 |
i_dist = m_creature->GetDistance(pUnit); i_boss_dist = NetherSpite->GetDistance(pUnit); if( i_dist + i_boss_dist <= boss_dist + 2 && i_dist < cur_dist && i_boss_dist < boss_dist) { // ... } |
Zitat von »"http://forums.scriptdev2.com/index.php?showtopic=3240"«
Suppose you have the two mob's positions given by (M1_x, M1_y) for mob 1 and (M2_x, M2_y) for mob 2, and the player given by (P_x, P_y). The midpoint of the two mobs is ( (M1_x+M2_x)/2, (M1_y+M2_y)/2 ). So if you want to test if the player is in a circle of radius r centered at the midpoint, you can test:
( P_x - ( M1_x + M2_x )/2 )^2 + ( P_y - ( M1_y + M2_y )/2 )^2 <= r^2
That should help remove some of the exactness of where you must be standing. You could even make the radius r be a function of how far apart the two mobs are... Perhaps a logistic curve so that the radius is not too small as the mobs get close together, yet is not infinitely getting larger as the mobs spread apart. Are there any simple functions with non-zero values at x=0, but converge to a linear function as x increases? Perhaps a piecewise function could be used for r, or even some series with those characteristics.
Edit:
I realized that the player doesn't have to be centered between the two mobs.. Just between them.. Similarly, you could check:
d >= abs( P1_x + P2_x * (M1_x+M2_x) / (M2_y) / (1-M1_y/M2_y) - M1_x - (M1_y/M2_y) * (M1_x+M2_x) / (1-M1_y/M2_y) ) / sqrt (1 + ((M1_x+M2_x) / (M2_y) / (1 - M1_y/M2_y))^2)
I'm sure that simplifies, but I'm too lazy to work through it right now. Just worked it out quickly in Notepad. If anyone has access to Mathematica or a pen-and-paper, they may get better results on this slightly more complicated equation. Comes from finding the line between the two mobs in the form Ax+By+C=0 and then using the formula for the perpendicular distance to (m,n):
d = abs( m*A + n*B + C) / sqrt( A^2 + B^2)
Werbeanzeige