Skip to content

Commit 08f35ab

Browse files
feat: able to change character and camera direction
1 parent a1a00ab commit 08f35ab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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.34",
3+
"version": "1.0.35",
44
"author": "Erdong Chen",
55
"license": "MIT",
66
"description": "A floating rigibody character controller for R3F",

src/Ecctrl.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ export default function Ecctrl({
2626
capsuleHalfHeight = 0.35,
2727
capsuleRadius = 0.3,
2828
floatHeight = 0.3,
29+
characterInitDir = 0, // in rad
2930
followLight = false,
3031
// Follow camera setups
3132
camInitDis = -5,
3233
camMaxDis = -7,
3334
camMinDis = -0.7,
35+
camInitDir = 0, // in rad
3436
// Base control setups
3537
maxVelLimit = 2.5,
3638
turnVelMultiplier = 0.2,
@@ -57,7 +59,7 @@ export default function Ecctrl({
5759
// Slope Ray setups
5860
showSlopeRayOrigin = false,
5961
slopeMaxAngle = 1, // in rad
60-
slopeRayOriginOffest = capsuleRadius - 0.02,
62+
slopeRayOriginOffest = capsuleRadius - 0.03,
6163
slopeRayLength = capsuleRadius + 3,
6264
slopeRayDir = { x: 0, y: -1, z: 0 },
6365
slopeUpExtraForce = 0.1,
@@ -639,6 +641,13 @@ export default function Ecctrl({
639641
);
640642
}, [autoBalance]);
641643

644+
useEffect(() => {
645+
// Initialize character facing direction
646+
modelEuler.y = characterInitDir
647+
// Initialize camera facing direction
648+
pivot.rotation.y = camInitDir
649+
}, [])
650+
642651
useFrame((state, delta) => {
643652
// Character current position
644653
if (characterRef.current) {
@@ -1020,11 +1029,13 @@ export interface EcctrlProps extends RigidBodyProps {
10201029
capsuleHalfHeight?: number;
10211030
capsuleRadius?: number;
10221031
floatHeight?: number;
1032+
characterInitDir?: number;
10231033
followLight?: boolean;
10241034
// Follow camera setups
10251035
camInitDis?: number;
10261036
camMaxDis?: number;
10271037
camMinDis?: number;
1038+
camInitDir?: number;
10281039
// Base control setups
10291040
maxVelLimit?: number;
10301041
turnVelMultiplier?: number;

0 commit comments

Comments
 (0)