Skip to content

Commit 76146dd

Browse files
committed
feat: added bindToLookAt3D() which makes a transform look at another transform
1 parent c4f37fb commit 76146dd

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

fxgl-entity/src/main/kotlin/com/almasb/fxgl/entity/components/TransformComponent.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,22 @@ class TransformComponent(x: Double, y: Double, angle: Double, scaleX: Double, sc
359359
updateDirection()
360360
}
361361

362+
private var boundLookAt: TransformComponent? = null
363+
364+
fun bindToLookAt3D(other: TransformComponent) {
365+
boundLookAt = other
366+
}
367+
368+
fun unbindToLookAt3D() {
369+
boundLookAt = null
370+
}
371+
372+
override fun onUpdate(tpf: Double) {
373+
boundLookAt?.let {
374+
lookAt(it.position3D)
375+
}
376+
}
377+
362378
/**
363379
* Move forward on the XZ plane.
364380
* No Y movement.

fxgl-samples/src/main/java/sandbox/test3d/Collision3DSample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected void initGame() {
7171
.collidable()
7272
.buildAndAttach();
7373

74-
// TODO: camera follow entity, which smoothly continuously calls "look at" entity?
7574
var camera = getGameScene().getCamera3D();
7675
camera.getTransform().xProperty().bind(e.xProperty());
7776
camera.getTransform().yProperty().bind(e.yProperty().subtract(10));

fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/Camera3D.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Camera3D {
5656

5757
fun update(tpf: Double) {
5858
tpfMoveSpeed = tpf * moveSpeed
59+
60+
transform.onUpdate(tpf)
5961
}
6062

6163
fun moveForward() {

0 commit comments

Comments
 (0)