1
\$\begingroup\$

I am trying to create a battle royale circle gamemode within Arma3 that would work like in PUBG.

For anyone who doesn't know how it looks like:
enter image description here
Red circle should smoothly shrink into the blue one (that means sides that close to each other should move very slowly by adjusting speed of the red circle center)

Global variables:

Center = (getMarkerPos "marker_start"); // eg. [1000, 1000]
ClosingSpeed = 0.5;
CurrentRadius = 1000;
EndingRadius = 250;
Offset = 1;

Code for generating new circle:

// Determines maximum radius of a new circle
private _maxRadius = CurrentRadius * 0.7;
// Generates radius of the new circle
private _randomRadius = [_maxRadius * 0.6, _maxRadius] call BIS_fnc_randomNum;
// Generates new circle center
private _randomCenter = [CurrentRadius * 0.1, (CurrentRadius - _randomRadius)] call BIS_fnc_randomNum;
// Randomizes position of the new circle within the old one
FinalCenter = Center getPos [_randomCenter, random 360];
EndingRadius = _randomRadius;
ClosingSpeed = ClosingSpeed / 2;
// This number should be somehow calculated to make the closing circle animation work properly 
Offset = 0.75;

Shrinking code, executed every 100 ms:

// Decreases radius
CurrentRadius = CurrentRadius - ClosingSpeed;
// Gets the angle between two center points - in degrees
private _angle = ((FinalCenter select 1) - (Center select 1)) atan2 ((FinalCenter select 0) - (Center select 0));
if (CurrentRadius > EndingRadius) then {
    // This sets new position of the circle
    Center set [0, (Center select 0) + ((Offset * ClosingSpeed) * cos (_angle))];
    Center set [1, (Center select 1) + ((Offset * ClosingSpeed) * sin (_angle))];
};

Without the correct Offset it shrinks like this - center points (red circle center was moving at a wrong velocity):
(

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

This could be solved using a parametric equation.

P' = P + (t * D)

Where: P is the starting position of the outer circle. P' is the current position of the circle. t is (elapsed time / time it takes to shrink the circle) D is a vector from P to the center of the inner circle. Note: do not normalize this vector.

If t > 1, the circle has finished moving, so use that to trigger the next circle.

This will smoothly interpolate the position of the center and guarantee it ends where you want it.

\$\endgroup\$
3
  • \$\begingroup\$ Hello, could you please show an example in pseudo code? I have trouble understanding your explanation. \$\endgroup\$
    – Nicer
    Jul 16, 2020 at 16:56
  • \$\begingroup\$ I had a mistake in my code, your solutions works. Thank you very much kind sir. \$\endgroup\$
    – Nicer
    Jul 16, 2020 at 17:23
  • \$\begingroup\$ Glad it worked and thanks for the vote. I may add a drawing to this answer later and some formulas. \$\endgroup\$ Jul 16, 2020 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .