Skip to content

Commit 9b2933c

Browse files
feat: able to change body sensor size and pos
1 parent b958503 commit 9b2933c

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<div id="root"></div>
1313
<img class="controlKeys" src="./keyControls.png" alt="control keys">
1414
<p class="title">
15+
<a target="_blank" href="https://github.com/pmndrs/ecctrl">Ecctrl</a>
1516
Floating Character Controller Demo by
1617
<a target="_blank" href="https://github.com/ErdongChen-Andrew/CharacterControl">Andrew Chen</a>
1718
<br>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ecctrl",
3-
"version": "1.0.90",
3+
"version": "1.0.91",
44
"author": "Erdong Chen",
55
"license": "MIT",
66
"description": "A floating rigibody character controller for R3F",

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ EcctrlProps: {
164164
autoBalance: true, // Enable auto-balance
165165
autoBalanceSpringK: 0.3, // Auto-balance spring constant
166166
autoBalanceDampingC: 0.03, // Auto-balance damping coefficient
167-
autoBalanceSpringOnY: 0.5, // Auto-balance spring on Y-axis
168-
autoBalanceDampingOnY: 0.015, // Auto-balance damping on Y-axis
167+
autoBalanceSpringOnY: 0.5, // Auto-balance spring on Y-axis
168+
autoBalanceDampingOnY: 0.015, // Auto-balance damping on Y-axis
169169
// Animation temporary setups
170170
animated: false, // Enable animation
171171
// Mode setups
172172
mode: null, // Activate different ecctrl modes ("CameraBasedMovement" | "FixedCamera" | "PointToMove")
173173
// Customizable controller key setups
174174
controllerKeys: { forward: 12, backward: 13, leftward: 14, rightward: 15, jump: 2, action1: 11, action2: 3, action3: 1, action4: 0 },
175+
// Point-to-move setups
176+
bodySensorSize: [capsuleHalfHeight / 2, capsuleRadius], // cylinder body sensor [halfHeight, radius]
177+
bodySensorPosition: { x: 0, y: 0, z: capsuleRadius / 2 },
175178
// Other rigibody props from parent
176179
// Rigidbody props can be used here,
177180
// such as position, friction, gravityScale, etc.
@@ -420,7 +423,7 @@ pressButton1();
420423

421424
### Ecctrl Mode
422425

423-
Activate different modes in Ecctrl by including the desired mode inside Ecctrl component:
426+
Activate different modes in Ecctrl by including the desired mode inside Ecctrl component:
424427
`<Ecctrl mode="PointToMove">`.
425428

426429
#### 1. "PointToMove" Mode ([CodeSandbox Demo](https://codesandbox.io/p/sandbox/ecctrl-pointtomove-m9z6xh?file=%2Fsrc%2FMap.js%3A46%2C19))

src/Ecctrl.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
123123
mode = null,
124124
// Controller setups
125125
controllerKeys = { forward: 12, backward: 13, leftward: 14, rightward: 15, jump: 2, action1: 11, action2: 3, action3: 1, action4: 0 },
126+
// Point-to-move setups
127+
bodySensorSize = [capsuleHalfHeight / 2, capsuleRadius],
128+
bodySensorPosition = { x: 0, y: 0, z: capsuleRadius / 2 },
126129
// Other rigibody props from parent
127130
...props
128131
}: EcctrlProps, ref) => {
@@ -1478,8 +1481,9 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
14781481
<CylinderCollider
14791482
ref={bodySensorRef}
14801483
sensor
1481-
args={[capsuleHalfHeight / 2, capsuleRadius]}
1482-
position={[0, 0, capsuleRadius / 2]}
1484+
mass={0}
1485+
args={[bodySensorSize[0], bodySensorSize[1]]}
1486+
position={[bodySensorPosition.x, bodySensorPosition.y, bodySensorPosition.z]}
14831487
onIntersectionEnter={handleOnIntersectionEnter}
14841488
onIntersectionExit={handleOnIntersectionExit}
14851489
/>}
@@ -1589,6 +1593,9 @@ export interface EcctrlProps extends RigidBodyProps {
15891593
mode?: string;
15901594
// Controller setups
15911595
controllerKeys?: { forward?: number, backward?: number, leftward?: number, rightward?: number, jump?: number, action1?: number, action2?: number, action3?: number, action4?: number }
1596+
// Point-to-move setups
1597+
bodySensorSize?: Array<number>;
1598+
bodySensorPosition?: { x: number, y: number, z: number }
15921599
// Other rigibody props from parent
15931600
props?: RigidBodyProps;
15941601
};

0 commit comments

Comments
 (0)