Why is it colliding with the ball automatically?
This commit is contained in:
parent
e886bb1f4d
commit
7da67bceb0
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
<Exit "ball" "other">
|
<Exit "ball" "other">
|
||||||
<sprite "ball"
|
<sprite "ball"
|
||||||
<move <v 0.0 1.5 3.0>
|
<move <v 0.0 1.5 30.0>
|
||||||
<color 0.0 1.0 0.0
|
<color 0.0 1.0 0.0
|
||||||
<touchable <sphere>>>>>
|
<touchable <sphere>>>>>
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,5 @@
|
||||||
<floor <ground <v 300.0 300.0>>>>>
|
<floor <ground <v 300.0 300.0>>>>>
|
||||||
|
|
||||||
<Exit "home" "lobby">
|
<Exit "home" "lobby">
|
||||||
<sprite "home" <move <v 0.0 1.5 -5.0> <color 0.0 1.0 0.0 <touchable <sphere>>>>>
|
<sprite "home" <move <v 0.0 1.5 5.0> <color 1.0 0.0 0.0 <touchable <sphere>>>>>
|
||||||
]
|
]
|
||||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -24,7 +24,7 @@ import { uuid } from './uuid.js';
|
||||||
|
|
||||||
assertion type SceneHandle(ds: Embedded<Ref>);
|
assertion type SceneHandle(ds: Embedded<Ref>);
|
||||||
|
|
||||||
function interpretScene(myId: string, scene: Scene, rootMesh: Mesh, sceneDs: Ref) {
|
function interpretScene(myId: string, runningEngine: RunningEngine, rootMesh: Mesh, sceneDs: Ref) {
|
||||||
at sceneDs {
|
at sceneDs {
|
||||||
during Shapes.Sprite({ "name": $name: string }) => spawn named `sprite:${name}` {
|
during Shapes.Sprite({ "name": $name: string }) => spawn named `sprite:${name}` {
|
||||||
if (name === myId) {
|
if (name === myId) {
|
||||||
|
@ -32,15 +32,15 @@ function interpretScene(myId: string, scene: Scene, rootMesh: Mesh, sceneDs: Ref
|
||||||
} else {
|
} else {
|
||||||
console.log('+shape', name);
|
console.log('+shape', name);
|
||||||
on stop console.log('-shape', name);
|
on stop console.log('-shape', name);
|
||||||
spriteMain(name, scene, rootMesh, sceneDs);
|
spriteMain(name, runningEngine, rootMesh, sceneDs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function spriteMain(spriteName: string, scene: Scene, rootMesh: Mesh, sceneDs: Ref) {
|
function spriteMain(spriteName: string, runningEngine: RunningEngine, rootMesh: Mesh, sceneDs: Ref) {
|
||||||
at sceneDs {
|
at sceneDs {
|
||||||
let currentShape = ShapeTree.empty(spriteName, scene);
|
let currentShape = ShapeTree.empty(spriteName, runningEngine.scene);
|
||||||
currentShape.node.parent = rootMesh;
|
currentShape.node.parent = rootMesh;
|
||||||
on stop currentShape.remove();
|
on stop currentShape.remove();
|
||||||
during Shapes.Sprite({ "name": spriteName, "shape": $shape: Shapes.Shape }) => {
|
during Shapes.Sprite({ "name": spriteName, "shape": $shape: Shapes.Shape }) => {
|
||||||
|
@ -62,16 +62,18 @@ async function enterScene(
|
||||||
console.log('enterScene', sceneDs);
|
console.log('enterScene', sceneDs);
|
||||||
|
|
||||||
const rootMesh = new Mesh('--root-' + (+new Date()), runningEngine.scene);
|
const rootMesh = new Mesh('--root-' + (+new Date()), runningEngine.scene);
|
||||||
interpretScene(id, runningEngine.scene, rootMesh, sceneDs);
|
|
||||||
|
|
||||||
const camera = runningEngine.camera;
|
const camera = runningEngine.camera;
|
||||||
camera.applyGravity = false;
|
camera.applyGravity = false;
|
||||||
camera.position = runningEngine.options.initialPos.clone();
|
camera.position = runningEngine.options.initialPos.clone();
|
||||||
|
|
||||||
|
interpretScene(id, runningEngine, rootMesh, sceneDs);
|
||||||
|
|
||||||
let lastTouchTime = 0;
|
let lastTouchTime = 0;
|
||||||
let lastTouchSpriteName = "";
|
let lastTouchSpriteName = "";
|
||||||
camera.onCollide = (other: AbstractMesh) => {
|
camera.onCollide = (other: AbstractMesh) => {
|
||||||
if (other.metadata?.touchable) {
|
if (other.metadata?.touchable) {
|
||||||
|
console.log('collision', other.name, other.metadata);
|
||||||
const now = +new Date();
|
const now = +new Date();
|
||||||
const touched = other.metadata?.spriteName ?? "";
|
const touched = other.metadata?.spriteName ?? "";
|
||||||
if ((now - lastTouchTime > 500) || (lastTouchSpriteName !== touched)) {
|
if ((now - lastTouchTime > 500) || (lastTouchSpriteName !== touched)) {
|
||||||
|
|
Loading…
Reference in New Issue