Skip to content

Commit

Permalink
feat: infinity aim
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Dec 2, 2024
1 parent e5ddbc7 commit dced738
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { clamp } from 'lodash-es';
import { useRef } from 'react';
import {
ArrowHelper,
AxesHelper,
Group,
MeshStandardMaterial,
TextureLoader,
Expand All @@ -22,7 +21,6 @@ const emptyVector = new Vector2();
const modelDefinitions = await awaitableModelDefinitions;

export function SceneProps() {
const shellTargetHelper = useRef<AxesHelper>(null);
const shellPathHelper = useRef<ArrowHelper>(null);
const show = TankopediaPersistent.use(
(state) => state.showGrid && !state.showEnvironment,
Expand Down Expand Up @@ -81,7 +79,6 @@ export function SceneProps() {
if (
display !== TankopediaDisplay.ShootingRange ||
!playground.current ||
!shellTargetHelper.current ||
!shellPathHelper.current
) {
return;
Expand All @@ -94,15 +91,22 @@ export function SceneProps() {
true,
);

if (intersections.length === 0) return;
let length: number;
let direction: Vector3;

const target = intersections[0].point;
const path = target.clone().sub(shellOrigin);
const direction = path.clone().normalize();
if (intersections.length === 0) {
length = 1000;
direction = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
} else {
const target = intersections[0].point;
const path = target.clone().sub(shellOrigin);

length = path.length();
direction = path.clone().normalize();
}

shellTargetHelper.current.position.copy(intersections[0].point);
shellPathHelper.current.setDirection(direction);
shellPathHelper.current.setLength(path.length());
shellPathHelper.current.setLength(length);

const [pitch, yaw] = applyPitchYawLimits(
Math.asin(direction.y),
Expand All @@ -124,7 +128,6 @@ export function SceneProps() {

{display === TankopediaDisplay.ShootingRange && (
<>
<axesHelper ref={shellTargetHelper} />
<arrowHelper ref={shellPathHelper} position={shellOrigin} />

<group ref={playground}>
Expand Down

0 comments on commit dced738

Please sign in to comment.