package gameEngine.entites.gameComponents; import gameEngine.Time; import gameEngine.entites.Entity; public class Physics extends GameComponent{ private Entity entity; public boolean useGravity = true; private float gravity = 9.8f; // 地球の重力加速度を使用 private float velocityY = 0; // Y軸方向の速度 Resetしなければ速度が引き継がれる public Physics(Entity entity){ this.entity = entity; } @Override public GameComponent copy() { return this; } public void update() { if (useGravity) { float deltaTime = Time.deltaTime; velocityY += gravity * deltaTime; float y = entity.transform.position.y; entity.transform.setPosition(entity.transform.position.x, y + velocityY * deltaTime, entity.transform.position.z); } } public void reset() { velocityY = 0; } }