forked from LeenkxTeam/Leenkx_Examples
update
This commit is contained in:
2
script_camera_lerp/README.md
Normal file
2
script_camera_lerp/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
Use keys `A` and `D` to rotate the cube.
|
||||
The camera follows the cube smoothly with interpolation.
|
||||
26
script_camera_lerp/Sources/lnx/CameraTrait.hx
Normal file
26
script_camera_lerp/Sources/lnx/CameraTrait.hx
Normal file
@ -0,0 +1,26 @@
|
||||
package lnx;
|
||||
|
||||
import iron.object.Object;
|
||||
import iron.Scene;
|
||||
import iron.math.Quat;
|
||||
|
||||
class CameraTrait extends iron.Trait {
|
||||
|
||||
var cube:Object;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
cube = Scene.active.getChild("Cube");
|
||||
});
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
if(cube.transform.rot != object.transform.rot){
|
||||
var newRot = new Quat().lerp(cube.transform.rot, object.transform.rot, 0.9);
|
||||
object.transform.rot.setFrom(newRot);
|
||||
object.transform.buildMatrix();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
23
script_camera_lerp/Sources/lnx/MyTrait.hx
Normal file
23
script_camera_lerp/Sources/lnx/MyTrait.hx
Normal file
@ -0,0 +1,23 @@
|
||||
package lnx;
|
||||
|
||||
import iron.system.Input;
|
||||
import iron.math.Vec4;
|
||||
import iron.system.Time;
|
||||
|
||||
class MyTrait extends iron.Trait {
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
|
||||
var kb = Input.getKeyboard();
|
||||
|
||||
if(kb.down("a") || kb.down("left")){
|
||||
object.transform.rotate(new Vec4(0,0,1), -3 * Time.delta);
|
||||
} else if(kb.down("d") || kb.down("right")){
|
||||
object.transform.rotate(new Vec4(0,0,1), 3 * Time.delta);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
script_camera_lerp/script_camera_lerp.blend
Normal file
BIN
script_camera_lerp/script_camera_lerp.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user