TransWikia.com

Moving and shrinking circle to a circle inside of it (PUBG like zone)

Game Development Asked by Nicer on November 2, 2021

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):
(

One Answer

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.

Answered by GaleRazorwind on November 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP