mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed skateboard and mesh positioning
This commit is contained in:
parent
7220e3b388
commit
bdab2a5760
9 changed files with 83 additions and 45 deletions
|
|
@ -10,6 +10,11 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
function Doll (physicsEngine, uid) {
|
||||
|
||||
this.height = 43;
|
||||
this.width = 9;
|
||||
this.headHeight = 12;
|
||||
this.reachDistance = 20;
|
||||
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
|
||||
this.standing = false;
|
||||
|
|
@ -33,8 +38,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
Doll.prototype.getBodyDef = function() {
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.position.x = 220 / Settings.RATIO;
|
||||
bodyDef.position.y = 0 / Settings.RATIO;
|
||||
bodyDef.position.x = 0;
|
||||
bodyDef.position.y = 0;
|
||||
bodyDef.fixedRotation = true;
|
||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
|
|
@ -50,21 +55,25 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||
|
||||
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
headShape.SetRadius(5 / Settings.RATIO);
|
||||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -35 / Settings.RATIO));
|
||||
headShape.SetRadius(this.width / 2 / Settings.RATIO);
|
||||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO));
|
||||
fixtureDef.shape = headShape;
|
||||
fixtureDef.isSensor = false;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -19 / Settings.RATIO));
|
||||
bodyShape.SetAsOrientedBox(
|
||||
this.width / 2 / Settings.RATIO,
|
||||
(this.height - this.width) / 2 / Settings.RATIO,
|
||||
new Box2D.Common.Math.b2Vec2(0, -this.height / 2 / Settings.RATIO)
|
||||
);
|
||||
fixtureDef.shape = bodyShape;
|
||||
fixtureDef.isSensor = false;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
legsShape.SetRadius(5 / Settings.RATIO);
|
||||
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -3 / Settings.RATIO));
|
||||
legsShape.SetRadius(this.width / 2 / Settings.RATIO);
|
||||
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -this.width / 2 / Settings.RATIO));
|
||||
fixtureDef.shape = legsShape;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
fixtureDef.isSensor = false;
|
||||
|
|
@ -74,8 +83,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
fixtureDef.density = 0;
|
||||
|
||||
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
feetShape.SetRadius(4 / Settings.RATIO);
|
||||
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 2 / Settings.RATIO));
|
||||
feetShape.SetRadius((this.width - 1) / 2 / Settings.RATIO); // the -1 one prevents collisions with walls
|
||||
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 2 / Settings.RATIO)); // 2 is offset into ground
|
||||
fixtureDef.shape = feetShape;
|
||||
fixtureDef.isSensor = true;
|
||||
|
||||
|
|
@ -86,7 +95,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
grabSensorLeftShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(-10 / Settings.RATIO, -10 / Settings.RATIO));
|
||||
grabSensorLeftShape.SetAsOrientedBox(
|
||||
this.reachDistance / 2 / Settings.RATIO,
|
||||
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
-this.reachDistance / 2 / Settings.RATIO,
|
||||
-this.height / 2 / Settings.RATIO
|
||||
)
|
||||
);
|
||||
fixtureDef.shape = grabSensorLeftShape;
|
||||
fixtureDef.isSensor = true;
|
||||
fixtureDef.userData = {
|
||||
|
|
@ -97,7 +113,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
grabSensorRightShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(10 / Settings.RATIO, -10 / Settings.RATIO));
|
||||
grabSensorRightShape.SetAsOrientedBox(
|
||||
this.reachDistance / 2 / Settings.RATIO,
|
||||
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
this.reachDistance / 2 / Settings.RATIO,
|
||||
-this.height / 2 / Settings.RATIO
|
||||
)
|
||||
);
|
||||
fixtureDef.shape = grabSensorRightShape;
|
||||
fixtureDef.isSensor = true;
|
||||
|
||||
|
|
@ -129,7 +152,19 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
}
|
||||
|
||||
Doll.prototype.getPosition = function() {
|
||||
return this.body.GetPosition();
|
||||
var pos = this.body.GetPosition();
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y
|
||||
};
|
||||
};
|
||||
|
||||
Doll.prototype.getHeadPosition = function() {
|
||||
var pos = this.body.GetPosition();
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO
|
||||
};
|
||||
};
|
||||
|
||||
Doll.prototype.setFriction = function (friction) {
|
||||
|
|
@ -249,11 +284,10 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
var p = this.body.GetPosition();
|
||||
this.holdingItem.body.SetPosition(new Box2D.Common.Math.b2Vec2(
|
||||
p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + 5 / Settings.RATIO) * this.lookDirection),
|
||||
p.y - 1
|
||||
p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||
p.y - 1 // 1m in the air
|
||||
));
|
||||
this.holdingItem.flip(this.lookDirection);
|
||||
//this.holdingItem.body.SetAngle(Math.PI * 2 / 180 * 20 * -this.lookDirection);
|
||||
this.holdingItem.body.SetAngle((this.holdingItem.options.grabAngle || 0) * this.lookDirection);
|
||||
|
||||
var jointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ function (Parent, Box2D, Settings) {
|
|||
this.wheels = [
|
||||
this.addWheel(
|
||||
options.x + 8,
|
||||
options.y + 1.5
|
||||
options.y - 1.5
|
||||
),
|
||||
this.addWheel(
|
||||
options.x - 8,
|
||||
options.y + 1.5
|
||||
options.y - 1.5
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
@ -26,13 +26,13 @@ function (Parent, Box2D, Settings) {
|
|||
|
||||
Skateboard.prototype.createFixture = function () {
|
||||
|
||||
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = 1.5 / Settings.RATIO;
|
||||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(1.5 / Settings.RATIO)));
|
||||
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO)));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = itemShape;
|
||||
fixtureDef.shape = deckShape;
|
||||
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ define([
|
|||
for (var i = 0; i < tiles.length; i++) {
|
||||
var options = tiles[i];
|
||||
options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
||||
|
||||
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +117,7 @@ define([
|
|||
// o o o
|
||||
// o o o
|
||||
|
||||
this.levelObject = {
|
||||
this.levelObject = this.levelObject || {
|
||||
/*
|
||||
Material densities (g/cm^3):
|
||||
|
||||
|
|
@ -277,6 +276,7 @@ microwave: 3.744
|
|||
*/
|
||||
|
||||
[
|
||||
{s:1, x:0, y:0, r:0},
|
||||
{s:1, x:1, y:1, r:0},
|
||||
{s:1, x:3, y:18},
|
||||
{s:1, x:37, y:27},
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ function (Doll, Settings) {
|
|||
return this.doll.getPosition();
|
||||
}
|
||||
|
||||
Player.prototype.getHeadPosition = function () {
|
||||
if(!this.doll) return false;
|
||||
return this.doll.getHeadPosition();
|
||||
}
|
||||
|
||||
|
||||
Player.prototype.move = function (direction) {
|
||||
this.doll.move(direction);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue