Hello!
So, I want a several simple animations, like a “cube fly to up at 0.5 second”, or “cube constantly rotating at z Axis”.
How to create it behind code, and then run it via play method?
Thanks!
Hello!
So, I want a several simple animations, like a “cube fly to up at 0.5 second”, or “cube constantly rotating at z Axis”.
How to create it behind code, and then run it via play method?
Thanks!
3D is unfortunately more complicated than 2D, and Heaps is a rather barebones engine.
If you want a coded 3D animation in general, it will probably look something like this:
override function update( dt : Float ) {
// time is flying...
time += 0.6 * dt;
// move the camera position around the two cubes
var dist = 5;
s3d.camera.pos.set(Math.cos(time) * dist, Math.sin(time) * dist, dist * 0.7 * Math.sin(time));
// rotate the second cube along a given axis + angle
obj2.setRotationAxis(-0.5, 2, Math.cos(time), time + Math.PI / 2);
}
From: Base3D - Heaps.io Game Engine (play/see in browser)
(Though it is also the camera that moves here)
As you can see, it is set up very manually by code.
In 2D this would be a bit easier, you could use slide (an external library):
Though maybe you can still use slide for 3D?
You can also ask in our heaps section on discord for more ideas?
edit: this shows a simple rotation at least:
override function update(dt:Float) {
obj.rotate(0, 0, 0.12 * dt);
}