Tweak: better jumping
This commit is contained in:
parent
d36313df37
commit
56ec41a802
@ -128,7 +128,9 @@ export class MedievalMusicians extends SceneFeature {
|
|||||||
const planeJumpChance = 0.1;
|
const planeJumpChance = 0.1;
|
||||||
const jumpChance = 0.005;
|
const jumpChance = 0.005;
|
||||||
const jumpDuration = 0.5;
|
const jumpDuration = 0.5;
|
||||||
const jumpHeight = 2.0;
|
const jumpHeight = 1.0;
|
||||||
|
const jumpVariance = 1.0;
|
||||||
|
const jumpPlaneVariance = 2.0;
|
||||||
|
|
||||||
this.musicians.forEach(musicianObj => {
|
this.musicians.forEach(musicianObj => {
|
||||||
const { mesh } = musicianObj;
|
const { mesh } = musicianObj;
|
||||||
@ -175,6 +177,7 @@ export class MedievalMusicians extends SceneFeature {
|
|||||||
} else {
|
} else {
|
||||||
// --- Arrived at edge, start the plane jump ---
|
// --- Arrived at edge, start the plane jump ---
|
||||||
musicianObj.state = 'JUMPING_PLANE';
|
musicianObj.state = 'JUMPING_PLANE';
|
||||||
|
musicianObj.jumpHeight = jumpHeight + Math.random() * jumpPlaneVariance;
|
||||||
musicianObj.jumpStartPos = mesh.position.clone();
|
musicianObj.jumpStartPos = mesh.position.clone();
|
||||||
const targetPlane = musicianObj.currentPlane === 'stage' ? 'floor' : 'stage';
|
const targetPlane = musicianObj.currentPlane === 'stage' ? 'floor' : 'stage';
|
||||||
const targetArea = targetPlane === 'stage' ? stageArea : floorArea;
|
const targetArea = targetPlane === 'stage' ? stageArea : floorArea;
|
||||||
@ -192,7 +195,7 @@ export class MedievalMusicians extends SceneFeature {
|
|||||||
if (musicianObj.jumpProgress < 1) {
|
if (musicianObj.jumpProgress < 1) {
|
||||||
// Determine base height based on which half of the jump we're in
|
// Determine base height based on which half of the jump we're in
|
||||||
const baseHeight = musicianObj.jumpProgress < 0.5 ? musicianObj.jumpStartPos.y : musicianObj.jumpEndPos.y;
|
const baseHeight = musicianObj.jumpProgress < 0.5 ? musicianObj.jumpStartPos.y : musicianObj.jumpEndPos.y;
|
||||||
const arcHeight = Math.sin(musicianObj.jumpProgress * Math.PI) * jumpHeight;
|
const arcHeight = Math.sin(musicianObj.jumpProgress * Math.PI) * musicianObj.jumpHeight;
|
||||||
|
|
||||||
// Interpolate horizontal position
|
// Interpolate horizontal position
|
||||||
const horizontalProgress = musicianObj.jumpProgress;
|
const horizontalProgress = musicianObj.jumpProgress;
|
||||||
@ -215,7 +218,7 @@ export class MedievalMusicians extends SceneFeature {
|
|||||||
const jumpProgress = (time - musicianObj.jumpStartTime) / jumpDuration;
|
const jumpProgress = (time - musicianObj.jumpStartTime) / jumpDuration;
|
||||||
if (jumpProgress < 1) {
|
if (jumpProgress < 1) {
|
||||||
const baseHeight = area.y + musicianHeight/2;
|
const baseHeight = area.y + musicianHeight/2;
|
||||||
mesh.position.y = baseHeight + Math.sin(jumpProgress * Math.PI) * jumpHeight;
|
mesh.position.y = baseHeight + Math.sin(jumpProgress * Math.PI) * musicianObj.jumpHeight;
|
||||||
} else {
|
} else {
|
||||||
musicianObj.isJumping = false;
|
musicianObj.isJumping = false;
|
||||||
mesh.position.y = area.y + musicianHeight / 2;
|
mesh.position.y = area.y + musicianHeight / 2;
|
||||||
@ -223,6 +226,7 @@ export class MedievalMusicians extends SceneFeature {
|
|||||||
} else {
|
} else {
|
||||||
if (Math.random() < jumpChance && musicianObj.state !== 'JUMPING_PLANE' && musicianObj.state !== 'PREPARING_JUMP') {
|
if (Math.random() < jumpChance && musicianObj.state !== 'JUMPING_PLANE' && musicianObj.state !== 'PREPARING_JUMP') {
|
||||||
musicianObj.isJumping = true;
|
musicianObj.isJumping = true;
|
||||||
|
musicianObj.jumpHeight = jumpHeight + Math.random() * jumpVariance;
|
||||||
musicianObj.jumpStartTime = time;
|
musicianObj.jumpStartTime = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user