Skip to content

Commit

Permalink
added fall() api, updated readme, updated bablylonjs to 7.0.0, packag…
Browse files Browse the repository at this point in the history
…e to 0.4.4
  • Loading branch information
ssatguru committed Jul 24, 2024
1 parent b0b11ca commit 89092fa
Show file tree
Hide file tree
Showing 14 changed files with 2,072 additions and 100 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ let characterController = new CharacterController(player, camera, scene);
</script>
```

## API ( version 0.4.0 )
## API ( version 0.4.4 )

#### To Instantiate

Expand Down Expand Up @@ -252,6 +252,8 @@ let agMap:{} = {

- forwardFacing - Optional. If the avatar's face is forward facing (positive Z direction) set this to true. By default it is false.

Note: If camera is set to null then the camera will not follow the character and keybaord will not controll the character. You can use this for an NPC which you can move around programmatically. See the section on "Controlling Avatar programmatically".

If using animation ranges the player skeleton is expected to have the animation ranges named as follows

- idle
Expand All @@ -272,7 +274,8 @@ If using animation ranges the player skeleton is expected to have the animation
- strafeRightFast
- slideDown

If an animation is not provided then the controller will not play that animation and will continue playing the animation it was playing just before.
If a particular animation is not provided then the controller will not play that animation and will continue playing the animation it was playing just before.
Note that if no animations are provided then no animations will be played. This, thus, can be used to move an non skeleton based mesh around.

Note that there are some animations with name ending with string "Fast".
If these are not present then the controller will play the non-fast version but at twice the speed.
Expand Down Expand Up @@ -461,6 +464,7 @@ cc.turnRight(b: boolean);
cc.strafeLeft(b: boolean);
cc.strafeRight(b: boolean);
cc.jump(b: boolean);
cc.fall();
```

Example:
Expand All @@ -470,6 +474,10 @@ cc.walk(true); // will start walking the Avatar.
cc.walk(false); // will stop walking the Avatar.
```

A word about cc.fall(). The CharacterController doesn't constantly check if the user is "grounded". This is to prevent needless computation. Once the Avatar is on a ground/floor it assumes the Avatar will continue to stand on that ground/floor until the user uses keys to move the Avatar.
In some use cases the ground/floor might move away and thus leave the Avatar hanging in mid air. In such cases use cc.fall() to force the Avatar to fall to the next gound/floor below.


#### Enabling/Disabling the KeyBoard controll

Sometimes, when you are controlling the movement of the Avatar programmatically as shown above, you might want to disable the keyboard.
Expand Down Expand Up @@ -531,6 +539,31 @@ setStepOffset(0.5);
The avatar can only move up a step if the height of the step is less than or equal to the "stepOffset".
By default the value is 0.25.

#### To set/change the setup step sound.

```
setSound(Babylon.Sound);
```

Example

```
let sound = new BABYLON.Sound(
"footstep",
"./sounds/footstep_carpet_000.ogg",
scene,
() => {
cc.setSound(sound);
},
{ loop: false }
);
```

The above will load sound from file "footstep_carpet_000.ogg" and when loaded will set the Avatar step sound to that.
This sound will be played for all actions except idle.
The sound will be played twice per cycle of the animation.
The rate will be set automatically based on frames and fps of animation

#### To change avatar or skeleton at

```
Expand Down
244 changes: 244 additions & 0 deletions dist-old/CharacterController.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import { Skeleton, ArcRotateCamera, Vector3, Mesh, Scene, AnimationGroup, Sound } from "babylonjs";
export declare class CharacterController {
private _avatar;
private _skeleton;
private _camera;
private _scene;
getScene(): Scene;
private _gravity;
private _minSlopeLimit;
private _maxSlopeLimit;
private _sl1;
private _sl2;
private _stepOffset;
private _vMoveTot;
private _vMovStartPos;
private _actionMap;
private _cameraElastic;
private _cameraTarget;
private _noFirstPerson;
setSlopeLimit(minSlopeLimit: number, maxSlopeLimit: number): void;
setStepOffset(stepOffset: number): void;
setWalkSpeed(n: number): void;
setRunSpeed(n: number): void;
setBackSpeed(n: number): void;
setBackFastSpeed(n: number): void;
setJumpSpeed(n: number): void;
setLeftSpeed(n: number): void;
setLeftFastSpeed(n: number): void;
setRightSpeed(n: number): void;
setRightFastSpeed(n: number): void;
setTurnSpeed(n: number): void;
setTurnFastSpeed(n: number): void;
setGravity(n: number): void;
setAnimationGroups(agMap: {}): void;
setAnimationRanges(arMap: {}): void;
setActionMap(inActMap: ActionMap): string;
getActionMap(): ActionMap;
getSettings(): CCSettings;
setSettings(ccs: CCSettings): void;
private _setAnim;
enableBlending(n: number): void;
disableBlending(): void;
setWalkAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setRunAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setWalkBackAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setWalkBackFastAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setSlideBackAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setIdleAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setTurnRightAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setTurnRightFastAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setTurnLeftAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setTurnLeftFastAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setStrafeRightAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setStrafeRightFastAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setStrafeLeftAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setStrafeLeftFastAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setIdleJumpAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setRunJumpAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
setFallAnim(rangeName: string | AnimationGroup, rate: number, loop: boolean): void;
_stepSound: Sound;
setSound(sound: Sound): void;
setWalkKey(key: string): void;
setWalkBackKey(key: string): void;
setTurnLeftKey(key: string): void;
setTurnRightKey(key: string): void;
setStrafeLeftKey(key: string): void;
setStrafeRightKey(key: string): void;
setJumpKey(key: string): void;
setCameraElasticity(b: boolean): void;
setElasticiSteps(n: number): void;
makeObstructionInvisible(b: boolean): void;
setCameraTarget(v: Vector3): void;
cameraCollisionChanged(): void;
setNoFirstPerson(b: boolean): void;
private _checkAnimRanges;
private _checkFastAnims;
private _copySlowAnims;
private _mode;
private _saveMode;
setMode(n: number): void;
getMode(): number;
setTurningOff(b: boolean): void;
isTurningOff(): boolean;
private _isLHS_RHS;
private _signLHS_RHS;
private _setRHS;
private _ffSign;
private _rhsSign;
private _ff;
private _av2cam;
setFaceForward(b: boolean): void;
isFaceForward(): boolean;
private checkAGs;
private _containsAG;
private _getRoot;
private _started;
start(): void;
stop(): void;
private _stopAnim;
pauseAnim(): void;
resumeAnim(): void;
private _prevActData;
private _avStartPos;
private _grounded;
private _freeFallDist;
private _fallFrameCountMin;
private _fallFrameCount;
private _inFreeFall;
private _wasWalking;
private _wasRunning;
private _moveVector;
private _isAvFacingCamera;
private _moveAVandCamera;
private _soundLoopTime;
private _sndId;
private _jumpStartPosY;
private _jumpTime;
private _doJump;
private _calcJumpDist;
private _endJump;
private _areVectorsEqual;
private _verticalSlope;
private _movFallTime;
private _sign;
private _isTurning;
private _noRot;
private _doMove;
private _rotateAV2C;
private _rotateAVnC;
private _endFreeFall;
private _idleFallTime;
private _doIdle;
private _groundFrameCount;
private _groundFrameMax;
private _groundIt;
private _unGroundIt;
private _savedCameraCollision;
private _inFP;
private _updateTargetValue;
private _makeMeshInvisible;
private _visiblityMap;
private _restoreVisiblity;
private _ray;
private _rayDir;
private _cameraSkin;
private _prevPickedMeshes;
private _pickedMeshes;
private _makeInvisible;
private _elasticSteps;
private _alreadyInvisible;
private _handleObstruction;
private _isSeeAble;
private _move;
anyMovement(): boolean;
private _onKeyDown;
private _onKeyUp;
private _ekb;
isKeyBoardEnabled(): boolean;
enableKeyBoard(b: boolean): void;
private _addkeylistener;
private _removekeylistener;
walk(b: boolean): void;
walkBack(b: boolean): void;
walkBackFast(b: boolean): void;
run(b: boolean): void;
turnLeft(b: boolean): void;
turnLeftFast(b: boolean): void;
turnRight(b: boolean): void;
turnRightFast(b: boolean): void;
strafeLeft(b: boolean): void;
strafeLeftFast(b: boolean): void;
strafeRight(b: boolean): void;
strafeRightFast(b: boolean): void;
jump(): void;
fall(): void;
idle(): void;
private _act;
private _renderer;
private _handleKeyUp;
private _handleKeyDown;
private _isAG;
isAg(): boolean;
private _findSkel;
private _root;
setAvatar(avatar: Mesh, faceForward?: boolean): boolean;
getAvatar(): Mesh;
setAvatarSkeleton(skeleton: Skeleton): void;
private _skelDrivenByAG;
getSkeleton(): Skeleton;
private _hasAnims;
private _hasCam;
constructor(avatar: Mesh, camera: ArcRotateCamera, scene: Scene, actionMap?: {}, faceForward?: boolean);
}
export declare class ActionData {
id: string;
speed: number;
ds: number;
sound: Sound;
key: string;
dk: string;
name: string;
ag: AnimationGroup;
loop: boolean;
rate: number;
exist: boolean;
constructor(id?: string, speed?: number, key?: string);
reset(): void;
}
export declare class ActionMap {
walk: ActionData;
walkBack: ActionData;
walkBackFast: ActionData;
idle: ActionData;
idleJump: ActionData;
run: ActionData;
runJump: ActionData;
fall: ActionData;
turnLeft: ActionData;
turnLeftFast: ActionData;
turnRight: ActionData;
turnRightFast: ActionData;
strafeLeft: ActionData;
strafeLeftFast: ActionData;
strafeRight: ActionData;
strafeRightFast: ActionData;
slideBack: ActionData;
reset(): void;
}
export declare class CCSettings {
faceForward: boolean;
gravity: number;
minSlopeLimit: number;
maxSlopeLimit: number;
stepOffset: number;
cameraElastic: boolean;
elasticSteps: number;
makeInvisble: boolean;
cameraTarget: Vector3;
noFirstPerson: boolean;
topDown: boolean;
turningOff: boolean;
keyboard: boolean;
sound: Sound;
}
2 changes: 2 additions & 0 deletions dist-old/CharacterController.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist-old/CharacterController.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 89092fa

Please sign in to comment.