Is there a way to slow down game time, then speed it back up?
For instance, I want to really juice up a moment where a character lands a final blow and the game slows down to highlight it and showcases the hit for a moment, then back to full game speed.
For this you would typically make your animation speed dependent on delta time. Then it’s just a matter of applying a time scale. Here is a simple example:
MyScript.attributes.add('target', { type: 'vec3' });
MyScript.velocity = new Vec3();
MyScript.prototype.update = function(dt) {
var timeScale = 1;
this.move(dt * timeScale);
}
MyScript.prototype.move = function(dt) {
var velocity = MyScript.velocity;
// Distance we want to move per second in world units
var speed = 3;
// Get the direction to the target
velocity.sub2(this.target, this.entity.getPosition());
// The velocity is along this direction, at full speed
velocity.normalize();
velocity.scale(speed);
// Update entity's velocity taking into account delta time
this.entity.rigidbody.linearVelocity.copy(velocity.scale(dt));
}
Normally timeScale would be 1 and if you would want your entity to move in slow motion, say half of normal speed, all you would have to do is change timeScale to 0.5. This is by no means an optimized example but should give you an area to explore for your particular needs.