gaesup-world 0.4.0 → 0.4.2

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.
@@ -14,7 +14,7 @@ export type characterColliderType = {
14
14
  radius: number;
15
15
  diameter: number;
16
16
  };
17
- export declare function CharacterInnerRef({ children, refs, urls, position, euler, currentAnimation, }: {
17
+ export declare function CharacterInnerRef({ children, refs, urls, position, euler, currentAnimation, positionLerp, }: {
18
18
  children: ReactNode;
19
19
  refs: Partial<refsType>;
20
20
  urls: urlsType;
@@ -22,4 +22,5 @@ export declare function CharacterInnerRef({ children, refs, urls, position, eule
22
22
  euler?: THREE.Euler;
23
23
  animationRef?: Ref<Object3D<Object3DEventMap>>;
24
24
  currentAnimation?: string;
25
+ positionLerp?: number;
25
26
  }): import("react/jsx-runtime").JSX.Element;
@@ -20,9 +20,9 @@ export var calcCharacterColliderProps = function (characterSize) {
20
20
  };
21
21
  };
22
22
  export function CharacterInnerRef(_a) {
23
- var children = _a.children, refs = _a.refs, urls = _a.urls, position = _a.position, euler = _a.euler, currentAnimation = _a.currentAnimation;
23
+ var children = _a.children, refs = _a.refs, urls = _a.urls, position = _a.position, euler = _a.euler, currentAnimation = _a.currentAnimation, positionLerp = _a.positionLerp;
24
24
  var outerGroupRef = refs.outerGroupRef, rigidBodyRef = refs.rigidBodyRef, colliderRef = refs.colliderRef, innerGroupRef = refs.innerGroupRef;
25
25
  var size = useGltfAndSize({ url: urls.characterUrl }).size;
26
26
  var collider = calcCharacterColliderProps(size);
27
- return (_jsx(_Fragment, { children: collider && (_jsx(OuterGroupRef, { ref: outerGroupRef, children: _jsxs(RigidBodyRef, { ref: rigidBodyRef, name: "character", position: position, rotation: euler, children: [_jsx(CapsuleCollider, { ref: colliderRef, args: [collider.height, collider.radius], position: [0, collider.height + collider.radius, 0] }), _jsx(InnerGroupRef, { type: "character", ref: innerGroupRef, url: urls.characterUrl, currentAnimation: currentAnimation, children: children })] }) })) }));
27
+ return (_jsx(_Fragment, { children: collider && (_jsx(OuterGroupRef, { ref: outerGroupRef, children: _jsxs(RigidBodyRef, { ref: rigidBodyRef, name: "character", position: position, positionLerp: positionLerp, rotation: euler, children: [_jsx(CapsuleCollider, { ref: colliderRef, args: [collider.height, collider.radius], position: [0, collider.height + collider.radius, 0] }), _jsx(InnerGroupRef, { type: "character", ref: innerGroupRef, url: urls.characterUrl, currentAnimation: currentAnimation, children: children })] }) })) }));
28
28
  }
@@ -9,4 +9,5 @@ export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
9
9
  intangible: boolean;
10
10
  };
11
11
  onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
12
+ positionLerp?: number;
12
13
  } & import("react").RefAttributes<RapierRigidBody>>;
@@ -1,7 +1,15 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { RigidBody, euler, } from "@react-three/rapier";
3
- import { forwardRef } from "react";
3
+ import { forwardRef, useEffect, useState, } from "react";
4
4
  export var RigidBodyRef = forwardRef(function (_a, ref) {
5
- var children = _a.children, name = _a.name, position = _a.position, rotation = _a.rotation, userData = _a.userData, onCollisionEnter = _a.onCollisionEnter;
6
- return (_jsx(RigidBody, { colliders: false, ref: ref, name: name, position: position, rotation: euler().set(0, (rotation === null || rotation === void 0 ? void 0 : rotation.clone().y) || 0, 0), userData: userData, onCollisionEnter: onCollisionEnter, children: children }));
5
+ var children = _a.children, name = _a.name, position = _a.position, rotation = _a.rotation, userData = _a.userData, onCollisionEnter = _a.onCollisionEnter, positionLerp = _a.positionLerp;
6
+ var _b = useState(position), newPosition = _b[0], setNewPosition = _b[1];
7
+ useEffect(function () {
8
+ if (!positionLerp)
9
+ return;
10
+ setNewPosition(function (ordPosition) {
11
+ return ordPosition.lerp(position.clone(), positionLerp);
12
+ });
13
+ }, [position, positionLerp]);
14
+ return (_jsx(RigidBody, { colliders: false, ref: ref, name: name, position: positionLerp ? newPosition === null || newPosition === void 0 ? void 0 : newPosition.clone() : position, rotation: euler().set(0, (rotation === null || rotation === void 0 ? void 0 : rotation.clone().y) || 0, 0), userData: userData, onCollisionEnter: onCollisionEnter, children: children }));
7
15
  });
@@ -7,5 +7,6 @@ export type passiveCharacterPropsType = {
7
7
  currentAnimation: string;
8
8
  gravityScale?: number;
9
9
  children?: React.ReactNode;
10
+ positionLerp?: number;
10
11
  };
11
12
  export declare function PassiveCharacter(props: passiveCharacterPropsType): import("react/jsx-runtime").JSX.Element;
@@ -29,8 +29,7 @@ export function PassiveCharacter(props) {
29
29
  useFrame(function (_, delta) {
30
30
  if (innerGroupRef && innerGroupRef.current) {
31
31
  innerGroupRef.current.quaternion.rotateTowards(quat().setFromEuler(euler), 10 * delta);
32
- // innerGroupRef.current.position.copy(position);
33
32
  }
34
33
  });
35
- return (_jsx(CharacterInnerRef, { position: position, refs: refs, urls: props.urls, currentAnimation: props.currentAnimation, children: props.children }));
34
+ return (_jsx(CharacterInnerRef, { position: position, refs: refs, urls: props.urls, currentAnimation: props.currentAnimation, positionLerp: props.positionLerp, children: props.children }));
36
35
  }
@@ -52,7 +52,7 @@ export function normalDirection(_a) {
52
52
  }
53
53
  }
54
54
  export default function direction(prop) {
55
- var state = prop.state, _a = prop.worldContext, joystick = _a.joystick, mode = _a.mode, activeState = _a.activeState, control = _a.control, clicker = _a.clicker;
55
+ var _a = prop.worldContext, joystick = _a.joystick, mode = _a.mode, activeState = _a.activeState, control = _a.control, clicker = _a.clicker;
56
56
  if (mode.control === "normal") {
57
57
  normalDirection({ activeState: activeState, control: control, mode: mode, joystick: joystick, clicker: clicker });
58
58
  }
@@ -32,13 +32,8 @@ export default function impulse(prop) {
32
32
  impulse.setZ(F.z);
33
33
  }
34
34
  rigidBodyRef.current.applyImpulse(impulse, true);
35
- activeState.position =
36
- // activeState.position.copy(
37
- activeState.position
38
- .clone()
39
- .lerp(vec3(rigidBodyRef.current.translation()), 0.9);
40
- // );
41
- activeState.velocity.lerp(vec3(rigidBodyRef.current.linvel()), 0.9);
35
+ activeState.position = vec3(rigidBodyRef.current.translation());
36
+ activeState.velocity = vec3(rigidBodyRef.current.linvel());
42
37
  dispatch({
43
38
  type: "update",
44
39
  payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "@react-three/drei": "9.97.0",
23
23
  "@react-three/fiber": "8.15.16",
24
24
  "@react-three/rapier": "^1.2.1",
25
+ "@types/lodash": "^4.17.0",
25
26
  "@types/three": "^0.161.2",
26
27
  "gh-pages": "^6.1.1",
27
28
  "leva": "0.9.35",