Skip to content

Commit

Permalink
v0.0.2 Adds walk starting/stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
danfinlay committed Feb 11, 2013
1 parent 791aeef commit 92b7a06
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 16 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,25 @@ var walk = require('voxel-walk')
```
In your render loop you pass it a time value and a minecraft-skin object (as can be found in the minecraft-skin module available on npm).
```
var time = (Date.now() - startTime)/1000;
var render = function () {
var time = Date.now()/1000
walk.render(duck, time)
}
```
You can tell the skin to start or stop walking with either of these functions (call each only once, or the acceleration change will continually reset. You can test for walking state as well)
```
if(walk.isWalking()){
walk.stopWalking()
}else{
walk.startWalking()
}
```
By Default the walk is begun and ended in 1 second. You can change this value like so:
```
walk.acceleration = 1.5
```


If you want to run the demo, just run:
```
//If you don't have browserify installed:
Expand Down
11 changes: 6 additions & 5 deletions demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var isMouseDown = false;
var counter = 0;
var firstRender = true;

var startTime = Date.now();
//var startTime = Date.now();
var pausedTime = 0;
var isRotating = true;
var isPaused = false;
Expand All @@ -42,15 +42,16 @@ var isFunnyRunning = false;



var walk = require('./')
window.duckWalk = require('./')

var render = function () {
window.webkitRequestAnimationFrame(render, renderer.domElement);
var oldRad = rad;

var time = (Date.now() - startTime)/1000;
//var time = (Date.now() - startTime)/1000;
var time = Date.now()/1000;

walk.render(duck, time)
duckWalk.render(duck, time)

if(!isMouseDown) {
//mouseX*=0.95;
Expand Down Expand Up @@ -84,4 +85,4 @@ var skin = require('minecraft-skin')
window.duck = skin(THREE, 'neg.png')
scene.add(duck.createPlayerObject())

render()
render()
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
<body>

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/three.js/r55/three.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="bundle.js"></script>
</body>

<button id="startWalking">Start Walking</button>
<button id="stopWalking">Stop Walking</button>

<script>

$('#startWalking').click(function(e){
duckWalk.startWalking()
})
$('#stopWalking').click(function(e){
duckWalk.stopWalking()
})
</script>
</html>

46 changes: 37 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
var walkSpeed = 1.0
var startedWalking = 0.0
var stoppedWalking = 0.0
var walking = false
var acceleration = 1.0

exports.render = function(skin, time){
skin.head.rotation.y = Math.sin(time*1.5)/3;
skin.head.rotation.z = Math.sin(time)/2;

if(walking && time<startedWalking+acceleration){
walkSpeed = (time-startedWalking)/acceleration
}
if(!walking && time<stoppedWalking+acceleration){
walkSpeed = -1/acceleration * (time-stoppedWalking) + 1
}

skin.head.rotation.y = Math.sin(time*1.5)/3 * walkSpeed
skin.head.rotation.z = Math.sin(time)/2 * walkSpeed

skin.rightArm.rotation.z = 2 * Math.cos(0.6662 * time*10 + Math.PI);
skin.rightArm.rotation.x = 1 * (Math.cos(0.2812 * time*10) - 1);
skin.leftArm.rotation.z = 2 * Math.cos(0.6662 * time*10);
skin.leftArm.rotation.x = 1 * (Math.cos(0.2312 * time*10) + 1);
skin.rightArm.rotation.z = 2 * Math.cos(0.6662 * time*10 + Math.PI) * walkSpeed
skin.rightArm.rotation.x = 1 * (Math.cos(0.2812 * time*10) - 1) * walkSpeed
skin.leftArm.rotation.z = 2 * Math.cos(0.6662 * time*10) * walkSpeed
skin.leftArm.rotation.x = 1 * (Math.cos(0.2312 * time*10) + 1) * walkSpeed

skin.rightLeg.rotation.z = 1.4 * Math.cos(0.6662 * time*10);
skin.leftLeg.rotation.z = 1.4 * Math.cos(0.6662 * time*10 + Math.PI);
};
skin.rightLeg.rotation.z = 1.4 * Math.cos(0.6662 * time*10) * walkSpeed
skin.leftLeg.rotation.z = 1.4 * Math.cos(0.6662 * time*10 + Math.PI) * walkSpeed
}

exports.startWalking = function(){
walking = true
startedWalking = Date.now()/1000
}
exports.stopWalking = function(){
walking = false
stoppedWalking = Date.now()/1000
}
exports.isWalking = function(){
return walking
}

exports.acceleration = acceleration
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voxel-walk",
"version": "0.0.1",
"version": "0.0.2",
"description":"A simple walk animation for minecraft-skin characters.",
"dependencies": {
"voxel-engine": "0.5.3",
Expand Down
Binary file added preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 92b7a06

Please sign in to comment.