Effect Rotate With Parent (#5999)

* Effect Rotate With Parent

* Use Rotc

* Wording

* Base Rotation

* Rotate effect rotation with parent.
This commit is contained in:
Matthew Peng
2021-09-27 08:55:56 -07:00
committed by GitHub
parent 6fb7f4fe26
commit 083c21ea3f
4 changed files with 41 additions and 11 deletions

View File

@@ -1,29 +1,41 @@
package mindustry.entities.comp;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class ChildComp implements Posc{
@Import float x, y;
abstract class ChildComp implements Posc, Rotc{
@Import float x, y, rotation;
@Nullable Posc parent;
float offsetX, offsetY;
boolean rotWithParent;
float offsetX, offsetY, offsetPos, offsetRot;
@Override
public void add(){
if(parent != null){
offsetX = x - parent.getX();
offsetY = y - parent.getY();
if(rotWithParent && parent instanceof Rotc r){
offsetPos = -r.rotation();
offsetRot = rotation - r.rotation();
}
}
}
@Override
public void update(){
if(parent != null){
x = parent.getX() + offsetX;
y = parent.getY() + offsetY;
if(rotWithParent && parent instanceof Rotc r){
x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY);
y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY);
rotation = r.rotation() + offsetRot;
}else{
x = parent.getX() + offsetX;
y = parent.getY() + offsetY;
}
}
}
}