gaesup-world 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { V3 } from "../../utils";
|
|
3
|
+
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
|
|
4
|
+
export function useMovePoint() {
|
|
5
|
+
var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker;
|
|
6
|
+
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
7
|
+
var move = function (position, isRun) {
|
|
8
|
+
var originPoint = activeState.position;
|
|
9
|
+
var newAngle = Math.atan2(position.z - originPoint.z, position.x - originPoint.x);
|
|
10
|
+
var norm = Math.sqrt(Math.pow(position.z - originPoint.z, 2) +
|
|
11
|
+
Math.pow(position.x - originPoint.x, 2));
|
|
12
|
+
if (norm < 2)
|
|
13
|
+
return;
|
|
14
|
+
dispatch({
|
|
15
|
+
type: "update",
|
|
16
|
+
payload: {
|
|
17
|
+
clicker: {
|
|
18
|
+
point: V3(position.x, 0, position.z),
|
|
19
|
+
angle: newAngle,
|
|
20
|
+
isOn: true,
|
|
21
|
+
isRun: isRun,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
// 거리 계산
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
var originPoint = activeState.position;
|
|
29
|
+
var newPosition = clicker.point;
|
|
30
|
+
var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
|
|
31
|
+
Math.pow(newPosition.x - originPoint.x, 2));
|
|
32
|
+
if (norm < 1) {
|
|
33
|
+
clicker.isOn = false;
|
|
34
|
+
dispatch({
|
|
35
|
+
type: "update",
|
|
36
|
+
payload: {
|
|
37
|
+
clicker: clicker,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, [activeState.position, clicker.point]);
|
|
42
|
+
return {
|
|
43
|
+
move: move,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -4,7 +4,8 @@ export function useTeleport() {
|
|
|
4
4
|
var refs = useContext(GaesupWorldContext).refs;
|
|
5
5
|
var Teleport = function (position) {
|
|
6
6
|
var _a, _b;
|
|
7
|
-
|
|
7
|
+
if (refs && refs.rigidBodyRef && refs.rigidBodyRef.current)
|
|
8
|
+
(_b = (_a = refs.rigidBodyRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.setTranslation(position, true);
|
|
8
9
|
};
|
|
9
10
|
return {
|
|
10
11
|
Teleport: Teleport,
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export { useFocus } from "./gaesup/hooks/useFocus";
|
|
|
22
22
|
export { useGaesupAnimation } from "./gaesup/hooks/useGaesupAnimation";
|
|
23
23
|
export { useGaesupController } from "./gaesup/hooks/useGaesupController";
|
|
24
24
|
export * as useJoyStick from "./gaesup/hooks/useJoyStick";
|
|
25
|
+
export { useMovePoint } from "./gaesup/hooks/useMovePoint";
|
|
25
26
|
export { usePushKey } from "./gaesup/hooks/usePushKey";
|
|
26
27
|
export { useRideable } from "./gaesup/hooks/useRideable";
|
|
27
28
|
export { useTeleport } from "./gaesup/hooks/useTeleport";
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { useFocus } from "./gaesup/hooks/useFocus";
|
|
|
22
22
|
export { useGaesupAnimation } from "./gaesup/hooks/useGaesupAnimation";
|
|
23
23
|
export { useGaesupController } from "./gaesup/hooks/useGaesupController";
|
|
24
24
|
export * as useJoyStick from "./gaesup/hooks/useJoyStick";
|
|
25
|
+
export { useMovePoint } from "./gaesup/hooks/useMovePoint";
|
|
25
26
|
export { usePushKey } from "./gaesup/hooks/usePushKey";
|
|
26
27
|
export { useRideable } from "./gaesup/hooks/useRideable";
|
|
27
28
|
export { useTeleport } from "./gaesup/hooks/useTeleport";
|
package/index.ts
CHANGED