Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / gameComponents / Physics.java
package gameEngine.entites.gameComponents;

import gameEngine.Time;
import gameEngine.entites.GameObject;

public class Physics extends GameComponent{

    private GameObject parent;
    public boolean useGravity = true;
    private float gravity = 9.8f;  // 地球の重力加速度を使用
    private float velocityY = 0;    // Y軸方向の速度 Resetしなければ速度が引き継がれる

    public Physics(GameObject parent){
        this.parent = parent;
    }

    @Override
    public GameComponent copy() {
        return this;
    }

    public void update() {
        if (useGravity) {
            float deltaTime = Time.deltaTime;

            velocityY += gravity * deltaTime;

            float y = parent.transform.position.y;
            parent.transform.setPosition(parent.transform.position.x, y + velocityY * deltaTime, parent.transform.position.z);
        }
    }

    public void reset() {
        velocityY = 0;
    }
}