Skip to content

Commit

Permalink
feat: added bindToLookAt3D() which makes a transform look at another …
Browse files Browse the repository at this point in the history
…transform
  • Loading branch information
AlmasB committed Sep 19, 2022
1 parent c4f37fb commit 76146dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,22 @@ class TransformComponent(x: Double, y: Double, angle: Double, scaleX: Double, sc
updateDirection()
}

private var boundLookAt: TransformComponent? = null

fun bindToLookAt3D(other: TransformComponent) {
boundLookAt = other
}

fun unbindToLookAt3D() {
boundLookAt = null
}

override fun onUpdate(tpf: Double) {
boundLookAt?.let {
lookAt(it.position3D)
}
}

/**
* Move forward on the XZ plane.
* No Y movement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected void initGame() {
.collidable()
.buildAndAttach();

// TODO: camera follow entity, which smoothly continuously calls "look at" entity?
var camera = getGameScene().getCamera3D();
camera.getTransform().xProperty().bind(e.xProperty());
camera.getTransform().yProperty().bind(e.yProperty().subtract(10));
Expand Down
2 changes: 2 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/Camera3D.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Camera3D {

fun update(tpf: Double) {
tpfMoveSpeed = tpf * moveSpeed

transform.onUpdate(tpf)
}

fun moveForward() {
Expand Down

0 comments on commit 76146dd

Please sign in to comment.