topical media & game development
mobile-query-three-plugins-ogsworkshop-examples-game025.htm / htm
<!--
Make character run only when he moves
-->
<!doctype html><title>Minimal tQuery Page</title>
<script src="../../../build/tquery-bundle-require.js"></script>
<body><script>
require(['tquery.minecraft', 'tquery.skymap', 'tquery.grassground', 'tquery.keyboard'], function(){
// create world
var world = tQuery.createWorld().boilerplate().start();
// add a skybox
tQuery.createSkymap('skybox').addTo(world);
// add a ground
var ground = tQuery.createGrassGround({
textureRepeatX : 20,
textureRepeatY : 20,
}).addTo(world)
.scale(80);
ground.get(0).material.map.anisotropy = 16;
// add minecraft char
var character = tQuery.createMinecraftChar().addTo(world);
// ad a keyboard control
tQuery.createMinecraftCharKeyboard2({
object3D : character.object3D('root'),
lateralMove : 'rotationY'
});
// make it run only if it move
var bodyAnims = new tQuery.MinecraftCharAnimations(character);
var mesh = character.object3D('root')
var prevPosition= tQuery.createVector3();
world.loop().hook(function(){
// compute velocity
var velocity = mesh.position().clone().subSelf(prevPosition);
// pick animation based
if( velocity.length() ){
bodyAnims.start('run')
}else{
bodyAnims.start('stand')
}
// update player.prevPosition/player.prevRotation
prevPosition.copy( mesh.position() )
})
})
</script></body>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.