|
13 | 13 |
|
14 | 14 | ## New Features
|
15 | 15 |
|
16 |
| -### (2023-10-02) Pmndrs/ecctrl & npm package: |
| 16 | +### (2023-11-18) EcctrlJoystick: |
17 | 17 |
|
18 |
| -- The character controller now integrated with [pmndrs/ecctrl](https://github.com/pmndrs/ecctrl) |
| 18 | +- Ecctrl now supports touch screen control! |
19 | 19 |
|
20 |
| -- You can easily install the npm package using the following command: |
21 |
| - |
22 |
| -```bash |
23 |
| -npm install ecctrl |
24 |
| -``` |
25 |
| - |
26 |
| -To get started, import `Ecctrl` and `EcctrlAnimation`, then wrap your character model within `<Ecctrl>`: |
| 20 | +- You can easily import and use the built-in 3D joystick. |
| 21 | + (note: place EcctrlJoystick outside of the canvas component) |
27 | 22 |
|
28 | 23 | ```js
|
29 |
| -import Ecctrl, {EcctrlAnimation} from 'ecctrl' |
30 |
| -... |
31 |
| - <Ecctrl> |
32 |
| - <CharacterModel/> |
33 |
| - </Ecctrl> |
34 |
| -... |
| 24 | +import Ecctrl, {EcctrlJoystick} from 'ecctrl' |
| 25 | +//... |
| 26 | + <EcctrlJoystick /> |
| 27 | + <Canvas> |
| 28 | + {/* ... */} |
| 29 | + </Canvas> |
| 30 | +//... |
35 | 31 | ```
|
36 | 32 |
|
| 33 | +- For more detailed settings, including lights, materials, and textures, please refer to the following sections. |
| 34 | + |
37 | 35 | - Additionally, I've prepared a simple [Ecctrl CodeSandbox](https://codesandbox.io/s/ecctrl-w-o-animations-3k3zxt) for online testing and demostration.
|
38 | 36 |
|
39 | 37 | - Also, here is another [Ecctrl CodeSandbox](https://codesandbox.io/s/ecctrl-with-animations-nr4493) showcasing character animation functionality.
|
40 | 38 |
|
41 |
| -[](https://codesandbox.io/s/ecctrl-w-o-animations-3k3zxt) |
| 39 | +[](https://codesandbox.io/s/ecctrl-w-o-animations-3k3zxt) |
42 | 40 |
|
43 | 41 | Check out the [featurelog.md](/featurelog.md) for details on previous updates and features.
|
44 | 42 |
|
@@ -127,10 +125,12 @@ EcctrlProps: {
|
127 | 125 | camInitDis: -5, // Initial camera distance
|
128 | 126 | camMaxDis: -7, // Maximum camera distance
|
129 | 127 | camMinDis: -0.7, // Minimum camera distance
|
130 |
| - camInitDir: 0, // Camera initial position direction (in rad) |
131 |
| - camMoveSpeed = 1, // Camera moving speed multiplier |
132 |
| - camZoomSpeed = 1, // Camera zooming speed multiplier |
133 |
| - camCollisionOffset = 0.7, // Camera collision offset |
| 128 | + camInitDir: { x: 0, y: 0, z: 0 }, // Camera initial rotation direction (in rad) |
| 129 | + camTargetPos: { x: 0, y: 0, z: 0 }, // Camera target position |
| 130 | + camMoveSpeed: 1, // Camera moving speed multiplier |
| 131 | + camZoomSpeed: 1, // Camera zooming speed multiplier |
| 132 | + camCollision: true, // Camera collision active/deactive |
| 133 | + camCollisionOffset: 0.7, // Camera collision offset |
134 | 134 | // Follow light setups
|
135 | 135 | followLightPos: { x: 20, y: 30, z: 10 }, // Follow light position
|
136 | 136 | // Base control setups
|
@@ -158,7 +158,7 @@ EcctrlProps: {
|
158 | 158 | dampingC: 0.08, // Damping coefficient
|
159 | 159 | // Slope Ray setups
|
160 | 160 | showSlopeRayOrigin: false, // Show slope ray origin
|
161 |
| - slopeMaxAngle = 1, // in rad, the max walkable slope angle |
| 161 | + slopeMaxAngle: 1, // in rad, the max walkable slope angle |
162 | 162 | slopeRayOriginOffest: capsuleRadius - 0.03, // Slope ray origin offset
|
163 | 163 | slopeRayLength: capsuleRadius + 3, // Slope ray length
|
164 | 164 | slopeRayDir: { x: 0, y: -1, z: 0 }, // Slope ray direction
|
@@ -306,6 +306,114 @@ const action4Animation = useGame((state) => state.action4);
|
306 | 306 | //const additionalAnimation = useGame((state) => state.triggerFunction);
|
307 | 307 | ```
|
308 | 308 |
|
| 309 | +### EcctrlJoystick and Touch buttons |
| 310 | + |
| 311 | +To get start, simply import `EcctrlJoystick` from `ecctrl` |
| 312 | + |
| 313 | +```js |
| 314 | +import { EcctrlJoystick } from "ecctrl"; |
| 315 | +``` |
| 316 | + |
| 317 | +Place `<EcctrlJoystick>` outside of your canvas component, and you're done! |
| 318 | + |
| 319 | +```js |
| 320 | +//... |
| 321 | + <EcctrlJoystick /> |
| 322 | + <Canvas> |
| 323 | + {/* ... */} |
| 324 | + </Canvas> |
| 325 | +//... |
| 326 | +``` |
| 327 | + |
| 328 | +You can also add lights or additional meshs like so (note: this will create components twice, once inside the joystick's scene, another inside the buttons' scene, so keep an eye on performance): |
| 329 | + |
| 330 | +```js |
| 331 | +//... |
| 332 | + <EcctrlJoystick> |
| 333 | + <ambientLight /> |
| 334 | + <mesh> |
| 335 | + <boxGeometry args={[1,1,1]} /> |
| 336 | + </mesh> |
| 337 | + </EcctrlJoystick> |
| 338 | + <Canvas> |
| 339 | + {/* ... */} |
| 340 | + </Canvas> |
| 341 | +//... |
| 342 | +``` |
| 343 | + |
| 344 | +Additionally, you can change components' material, geometry, or texture as you like: |
| 345 | + |
| 346 | +```js |
| 347 | +//... |
| 348 | + <EcctrlJoystick |
| 349 | + joystickBaseProps={{ |
| 350 | + receiveShadow: true, |
| 351 | + material: new THREE.MeshStandardMaterial({ color: "grey" }) |
| 352 | + }} |
| 353 | + /> |
| 354 | + <Canvas> |
| 355 | + {/* ... */} |
| 356 | + </Canvas> |
| 357 | +//... |
| 358 | +``` |
| 359 | + |
| 360 | +Here are all the properties you can play with for `<EcctrlJoystick>`: |
| 361 | + |
| 362 | +```js |
| 363 | +EcctrlJoystickProps: { |
| 364 | + // Joystick props |
| 365 | + children?: ReactNode; |
| 366 | + joystickPositionLeft?: number; // joystick div container position left |
| 367 | + joystickPositionBottom?: number; // joystick div container position bottom |
| 368 | + joystickHeightAndWidth?: number; // joystick div container height and width |
| 369 | + joystickCamZoom?: number; // camera zoom level for the joystick |
| 370 | + joystickCamPosition?: [x: number, y: number, z: number]; // camera position for the joystick |
| 371 | + joystickBaseProps?: ThreeElements['mesh']; // custom properties for the joystick's base mesh |
| 372 | + joystickStickProps?: ThreeElements['mesh']; // custom properties for the joystick's stick mesh |
| 373 | + joystickHandleProps?: ThreeElements['mesh']; // custom properties for the joystick's handle mesh |
| 374 | + |
| 375 | + // Touch buttons props |
| 376 | + buttonNumber?: number; // Number of buttons (max 5) |
| 377 | + buttonPositionRight?: number; // buttons div container position right |
| 378 | + buttonPositionBottom?: number; // buttons div container position bottom |
| 379 | + buttonHeightAndWidth?: number; // buttons div container height and width |
| 380 | + buttonCamZoom?: number; // camera zoom level for the buttons |
| 381 | + buttonCamPosition?: [x: number, y: number, z: number]; // camera position for the buttons |
| 382 | + buttonGroup1Position?: [x: number, y: number, z: number]; // button 1 posiiton in 3D scene |
| 383 | + buttonGroup2Position?: [x: number, y: number, z: number]; // button 2 posiiton in 3D scene |
| 384 | + buttonGroup3Position?: [x: number, y: number, z: number]; // button 3 posiiton in 3D scene |
| 385 | + buttonGroup4Position?: [x: number, y: number, z: number]; // button 4 posiiton in 3D scene |
| 386 | + buttonGroup5Position?: [x: number, y: number, z: number]; // button 5 posiiton in 3D scene |
| 387 | + buttonLargeBaseProps?: ThreeElements['mesh']; // custom properties for the buttons' large base mesh |
| 388 | + buttonSmallBaseProps?: ThreeElements['mesh']; // custom properties for the buttons' small base mesh |
| 389 | + buttonTop1Props?: ThreeElements['mesh']; // custom properties for the button 1 top mesh (large button) |
| 390 | + buttonTop2Props?: ThreeElements['mesh']; // custom properties for the button 2 top mesh (large button) |
| 391 | + buttonTop3Props?: ThreeElements['mesh']; // custom properties for the button 3 top mesh (small button) |
| 392 | + buttonTop4Props?: ThreeElements['mesh']; // custom properties for the button 4 top mesh (small button) |
| 393 | + buttonTop5Props?: ThreeElements['mesh']; // custom properties for the button 5 top mesh (small button) |
| 394 | +}; |
| 395 | +``` |
| 396 | + |
| 397 | +### Using your own joystick or buttons |
| 398 | + |
| 399 | +If you prefer to use your custom joystick or buttons, you can leverage the `useJoystickControls` hook from `ecctrl`. Import the hook and call the appropriate functions:: |
| 400 | + |
| 401 | +```js |
| 402 | +import { useJoystickControls } from "ecctrl"; |
| 403 | +//... |
| 404 | +const setJoystick = useJoystickControls((state) => state.setJoystick); |
| 405 | +const resetJoystick = useJoystickControls((state) => state.resetJoystick); |
| 406 | +const pressButton1 = useJoystickControls((state) => state.pressButton1); |
| 407 | +const releaseAllButtons = useJoystickControls( |
| 408 | + (state) => state.releaseAllButtons |
| 409 | +); |
| 410 | +//... |
| 411 | +// call the proper fuctions |
| 412 | +setJoystick(joystickDis, joystickAng, runState) |
| 413 | +// or |
| 414 | +pressButton1(); |
| 415 | +``` |
| 416 | + |
309 | 417 | ## Contributions
|
310 | 418 |
|
311 | 419 | I appreciate your interest in this project! If you have any feedback, suggestions, or resources related to the controller, please feel free to share.
|
|
0 commit comments