Skip to content

Commit

Permalink
Aiming related improvements.
Browse files Browse the repository at this point in the history
Shooting logic was removed and replaced with tool handling logic - It was needed to be more generic. Check the demo project for more details https://github.com/NewKrok/three-tps-demo
  • Loading branch information
NewKrok committed Mar 22, 2022
1 parent 81c96d5 commit a9b83c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newkrok/three-tps",
"version": "0.0.5",
"version": "0.1.0",
"description": "TPS extension for THREE Game",
"exports": {
"./src/*": "./src/*"
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/NewKrok/three-tps#readme",
"dependencies": {
"@newkrok/three-game": "0.0.4"
"@newkrok/three-game": "0.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
39 changes: 18 additions & 21 deletions src/js/newkrok/three-tps/control/unit-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,18 @@ export const updateUnitController = ({ now, delta }) => {
_target.isShootTriggered = false;
}

_target.aimingPosition = _world
const cameraPosition = _world.camera.instance.getWorldPosition(
new THREE.Vector3()
);
const cameraDirection = _world.camera.instance.getWorldDirection(
new THREE.Vector3()
);
const aimingRayResult = _world
.getModule(MODULE_ID.OCTREE)
.worldOctree.rayIntersect(
new THREE.Ray(
_world.camera.instance.getWorldPosition(new THREE.Vector3()),
_world.camera.instance.getWorldDirection(new THREE.Vector3())
)
).position;
.worldOctree.rayIntersect(new THREE.Ray(cameraPosition, cameraDirection));
_target.aimingPosition =
aimingRayResult?.position ||
cameraPosition.add(cameraDirection.setLength(15));

const selectedTool = _target.getSelectedTool();
if (
Expand All @@ -353,20 +357,13 @@ export const updateUnitController = ({ now, delta }) => {
selectedWeaponType === WeaponType.RIFLE
) {
_target.isShootTriggered = true;

/* const shootingEffect = createParticleSystem(
effectsConfig[EffectId.SHOOTING]
);
projectileStartSocket.add(shootingEffect);
setTimeout(() => destroyParticleSystem(shootingEffect), 1000);*/

_world.getModule(MODULE_ID.PROJECTILES).shoot({
startPosition: _target
.getSocket(ModelSocketId.PROJECTILE_START)
.getWorldPosition(new THREE.Vector3()),
direction: selectedTool.getWorldDirection(new THREE.Vector3()),
scene: _world.scene,
});
const position = _target
.getRegisteredObject("projectileStart")
.object.getWorldPosition(new THREE.Vector3());
const direction = selectedTool.object.getWorldDirection(
new THREE.Vector3()
);
selectedTool?.on?.activate({ world: _world, position, direction });
}
}
};
7 changes: 3 additions & 4 deletions src/js/newkrok/three-tps/tps-world.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ export const createTPSWorld = ({
characterConfig,
camera: camera.instance,
characterTickRoutine: (character) => {
character.updateLookAtPosition({
position: character.useAim ? character.aimingPosition : null,
rotation: camera.getRotation(),
});
character.updateAimPosition(
character.useAim ? character.aimingPosition : null
);
},
})
.then((world) => {
Expand Down

0 comments on commit a9b83c8

Please sign in to comment.