# Rotate entities arround circle

Discussion in 'Help' started by felony13twelve, Nov 28, 2022.

1. ### felony13twelveCreeper

Messages:
2
I want to make such an animation as in the video - I know that I need cosine, sine, etc. but my knowledge does not allow me to write it, because I don't know geometry well. Please help me to do this.

2. ### PrimusZombie Pigman

Messages:
747
Start by spawning them in circle, then move by an angle offset.

3. ### LearXDCreeper

Messages:
3
GitHub:
learxd
I believe you already know how to generate entities, so let's get down to business, the Mathematics behind it.

To make a circle we're going to use the sine and cosine of an angle that will show us a position on the circle, then we're going to multiply both by the radius, since the default "radius" of sine and cosine is 1.

As the amount of items can vary, I made a calculation that will correctly distribute them in the circle...

Code: (I haven't programmed in pocketmine for a while, so I know the API works correctly, so please follow this code as a guide, not a solution...)

Code:
<?php

use pocketmine\item\Item;
use pocketmine\math\Vector3;

protected $items = []; protected$center;

protected $turns = 0; //Your constructor function public function __construct(array$items) {
$thos->items =$items;
$this->center = new Vector3(0,0,0); } //Your loop can be a ScheduleTask public function loop() {$pi = 2 * M_PI;
$cicles = 1 / sizeof($items);

foreach ( $items as$i => $item ) {$x = sin($pi * ($i * $cicles)) * RADIUS;$y = cos($pi* ($i * $cicles)) * RADIUS; // X, Y, Z (using only Y,Z)$item->teleport($this->center->add(0,$x, $y)); }$this->turns += $cicles;$this->items[] = array_shift($this->items); if ($this->turns >= 1) { //1 = 100%
// 1 turn completed, you can stop here
}
}

Primus likes this.