Skip to content

Commit

Permalink
New world module: Verlet integration - With this it's possible to lin…
Browse files Browse the repository at this point in the history
…k easily 2 objects without any physic library.

New world module: Octree car - Simple car physics based on spheres.
Breaking Change! Unit controller was renamed to player controller. It was needed since from now it can control anything.
Breaking Change! world.onUpdate now is available as world.on.update.
Breaking Change! Unit config is not an initial config anymore, from now it's part of the world config.
Possible to listen world.on.dispose.
Octree car related boilerplates were added.
Octree module can handle spheres by default.
Possible to create units without animations.
Missing dispose methods were added into: region module, collectibles module.
Pause related time fixes.
Dependency updates.
  • Loading branch information
NewKrok committed May 30, 2022
1 parent 52b892b commit 760f3d7
Show file tree
Hide file tree
Showing 15 changed files with 857 additions and 128 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newkrok/three-game",
"version": "0.6.1",
"version": "0.7.0",
"description": "ThreeJS based game engine",
"main": "src/js/newkrok/three-game/world.js",
"exports": {
Expand All @@ -23,9 +23,9 @@
},
"homepage": "https://github.com/NewKrok/three-game#readme",
"dependencies": {
"three": "0.140.2",
"@newkrok/three-utils": "0.2.0",
"detect-browser": "5.3.0"
"three": "^0.141.0",
"@newkrok/three-utils": "^0.3.0",
"detect-browser": "^5.3.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
29 changes: 29 additions & 0 deletions src/js/newkrok/three-game/boilerplates/car-boilerplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as THREE from "three";

export const basicCar = {
body: {
model: {},
width: 1.6,
height: 1.5,
length: 2.72,
offset: new THREE.Vector3(),
},
wheel: {
radius: 0.4,
mass: 50,
},
speedReductionByCollision: 0.85,
maxSpeed: 60,
maxReverseSpeed: 20,
accelerationForward: 0.07,
accelerationBackward: 0.04,
breakRatio: 0.99,
damping: 0.998,
friction: 0.999,
minAcceleration: 1,
steeringResetSpeed: 3,
maxSteeringSpeed: 5,
maxWheelAngle: Math.PI / 3,
frontWheelSpeedMultiplier: 1,
rearWheelSpeedMultiplier: 0.75,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { ButtonKey } from "@newkrok/three-game/src/js/newkrok/three-game/control/gamepad.js";
import { Key } from "@newkrok/three-game/src/js/newkrok/three-game/control/keyboard-manager.js";

export const PlayerActionId = {
PAUSE: "PAUSE",
FORWARD: "FORWARD",
BACKWARD: "BACKWARD",
LEFT: "LEFT",
RIGHT: "RIGHT",
JUMP: "JUMP",
SPRINT: "SPRINT",
TOOL_ACTION: "TOOL_ACTION",
CHOOSE_NEXT_TOOL: "CHOOSE_NEXT_TOOL",
CHOOSE_PREV_TOOL: "CHOOSE_PREV_TOOL",
...Array.from({ length: 10 }).reduce(
(prev, _, index) => ({
...prev,
[`CHOOSE_TOOL_${index}`]: `CHOOSE_TOOL_${index}`,
}),
{}
),
};

export const unitControllerConfig = {
actionConfig: [
{
actionId: PlayerActionId.PAUSE,
enableDuringPause: true,
keys: [Key.P],
gamepadButtons: [ButtonKey.Options],
},
{
actionId: PlayerActionId.FORWARD,
listenForDeactivation: true,
keys: [Key.W, Key.ARROW_UP],
gamepadButtons: [ButtonKey.Up],
axis: ButtonKey.LeftAxisY,
axisValidator: (v) => v < -0.1,
axisValueModifier: (v) => v * -1,
},
{
actionId: PlayerActionId.BACKWARD,
listenForDeactivation: true,
keys: [Key.S, Key.ARROW_DOWN],
gamepadButtons: [ButtonKey.Down],
axis: ButtonKey.LeftAxisY,
axisValidator: (v) => v > 0.1,
},
{
actionId: PlayerActionId.LEFT,
listenForDeactivation: true,
keys: [Key.A, Key.ARROW_LEFT],
gamepadButtons: [ButtonKey.Left],
axis: ButtonKey.LeftAxisX,
axisValidator: (v) => v < -0.1,
axisValueModifier: (v) => v * -1,
},
{
actionId: PlayerActionId.RIGHT,
listenForDeactivation: true,
keys: [Key.D, Key.ARROW_RIGHT],
gamepadButtons: [ButtonKey.Right],
axis: ButtonKey.LeftAxisX,
axisValidator: (v) => v > 0.1,
},
{
actionId: PlayerActionId.JUMP,
keys: [Key.SPACE],
gamepadButtons: [ButtonKey.ActionBottom],
},
],

handlers: [
{
actionId: PlayerActionId.PAUSE,
callback: ({ world }) => {
if (world.cycleData.isPaused) world.resume();
else world.pause();
},
},
{
actionId: PlayerActionId.JUMP,
callback: ({ target }) => {
if (target.onGround) target.jump();
},
},
],
};

export const carControllerConfig = {
actionConfig: [
{
actionId: PlayerActionId.PAUSE,
enableDuringPause: true,
keys: [Key.P],
gamepadButtons: [ButtonKey.Options],
},
{
actionId: PlayerActionId.FORWARD,
listenForDeactivation: true,
keys: [Key.W, Key.ARROW_UP],
gamepadButtons: [ButtonKey.Up],
axis: ButtonKey.LeftAxisY,
axisValidator: (v) => v < -0.1,
axisValueModifier: (v) => v * -1,
},
{
actionId: PlayerActionId.BACKWARD,
listenForDeactivation: true,
keys: [Key.S, Key.ARROW_DOWN],
gamepadButtons: [ButtonKey.Down],
axis: ButtonKey.LeftAxisY,
axisValidator: (v) => v > 0.1,
},
{
actionId: PlayerActionId.LEFT,
listenForDeactivation: true,
keys: [Key.A, Key.ARROW_LEFT],
gamepadButtons: [ButtonKey.Left],
axis: ButtonKey.LeftAxisX,
axisValidator: (v) => v < -0.1,
axisValueModifier: (v) => v * -1,
},
{
actionId: PlayerActionId.RIGHT,
listenForDeactivation: true,
keys: [Key.D, Key.ARROW_RIGHT],
gamepadButtons: [ButtonKey.Right],
axis: ButtonKey.LeftAxisX,
axisValidator: (v) => v > 0.1,
},
],

handlers: [
{
actionId: PlayerActionId.PAUSE,
callback: ({ world }) => {
if (world.cycleData.isPaused) world.resume();
else world.pause();
},
},
{
actionId: PlayerActionId.FORWARD,
callback: ({ target }) => {
target.accelerate();
},
},
{
actionId: PlayerActionId.BACKWARD,
callback: ({ target }) => {
target.reverse();
},
},
{
actionId: PlayerActionId.LEFT,
callback: ({ target }) => {
target.rotateLeft();
},
},
{
actionId: PlayerActionId.RIGHT,
callback: ({ target }) => {
target.rotateRight();
},
},
],
};

This file was deleted.

4 changes: 3 additions & 1 deletion src/js/newkrok/three-game/modules/module-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ export const WorldModuleId = {
PROJECTILES: "PROJECTILES",
COLLECTIBLE: "COLLECTIBLE",
REGION: "REGION",
VERLET_INTEGRATION: "VERLET_INTEGRATION",
OCTREE_CAR: "OCTREE_CAR",
PLAYER_CONTROLLER: "PLAYER_CONTROLLER",
};

export const UnitModuleId = {
AIMING: "AIMING",
UNIT_CONTROLLER: "UNIT_CONTROLLER",
ABILITIES: "ABILITIES",
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const create = ({ world, unit, config }) => {
(key) => (abilityStates[key].isActive = false)
);
const abilityState = abilityStates[ability];
abilityState.lastActivationTime = Date.now();
abilityState.lastActivationTime = world.cycleData.now;
abilityState.isActive = true;
},
deactivate: (ability) => {
Expand Down
4 changes: 3 additions & 1 deletion src/js/newkrok/three-game/unit/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export const createUnit = ({
world.scene.add( boxHelper );
*/

const mixer = new THREE.AnimationMixer(model);
const mixer = Object.keys(config.animations).length
? new THREE.AnimationMixer(model)
: null;

const addAnimation = (key) => {
const anim = getFBXSkeletonAnimation(config.animations[key]);
Expand Down
Loading

0 comments on commit 760f3d7

Please sign in to comment.