Skip to content

Commit 419874a

Browse files
feat: add followLightPos prop
1 parent 4b4f3a2 commit 419874a

File tree

3 files changed

+11
-5
lines changed

3 files changed

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

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ EcctrlProps: {
122122
capsuleRadius: 0.3, // Radius of the character capsule
123123
floatHeight: 0.3, // Height of the character when floating
124124
characterInitDir: 0, // Character initial facing direction (in rad)
125-
followLight: false, // Enable follow light mode
125+
followLight: false, // Enable follow light mode (name your light "followLight" before turn this on)
126126
// Follow camera setups
127127
camInitDis: -5, // Initial camera distance
128128
camMaxDis: -7, // Maximum camera distance
129129
camMinDis: -0.7, // Minimum camera distance
130130
camInitDir: 0, // Camera initial position direction (in rad)
131+
// Follow light setups
132+
followLightPos: { x: 20, y: 30, z: 10 }, // Follow light position
131133
// Base control setups
132134
maxVelLimit: 2.5, // Maximum velocity limit
133135
turnVelMultiplier: 0.2, // Turn velocity multiplier

src/Ecctrl.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const Ecctrl = forwardRef<RapierRigidBody, EcctrlProps>(({
3434
camMaxDis = -7,
3535
camMinDis = -0.7,
3636
camInitDir = 0, // in rad
37+
// Follow light setups
38+
followLightPos = { x: 20, y: 30, z: 10 },
3739
// Base control setups
3840
maxVelLimit = 2.5,
3941
turnVelMultiplier = 0.2,
@@ -696,9 +698,9 @@ const Ecctrl = forwardRef<RapierRigidBody, EcctrlProps>(({
696698
* Apply character position to directional light
697699
*/
698700
if (followLight && dirLight) {
699-
dirLight.position.x = currentPos.x + 20;
700-
dirLight.position.y = currentPos.y + 30;
701-
dirLight.position.z = currentPos.z + 10;
701+
dirLight.position.x = currentPos.x + followLightPos.x;
702+
dirLight.position.y = currentPos.y + followLightPos.y;
703+
dirLight.position.z = currentPos.z + followLightPos.z;
702704
dirLight.target = characterModelRef.current;
703705
}
704706

@@ -1076,6 +1078,8 @@ export interface EcctrlProps extends RigidBodyProps {
10761078
camMaxDis?: number;
10771079
camMinDis?: number;
10781080
camInitDir?: number;
1081+
// Follow light setups
1082+
followLightPos?: { x: number, y: number, z: number },
10791083
// Base control setups
10801084
maxVelLimit?: number;
10811085
turnVelMultiplier?: number;

0 commit comments

Comments
 (0)