BlueGit

blue-star speeltuin

Files

speeltuin / src / objects / caster.js

caster.js

caster.js 731 B Download Raw
1class Caster extends GameObject
2{
3 lastResult = {};
4 update (deltaTime)
5 {
6
7 if (!GameInput.mousePosition)
8 return;
9 this.collider.enabled = true;
10 if (this.collider.isInBounds(GameInput.mousePosition))
11 {
12 console.log("hoverin");
13 }
14 }
15
16 draw (context)
17 {
18 if (!GameInput.mousePosition)
19 return;
20
21 super.draw(context);
22 let origin = this.transform.position;
23 let dir = GameInput.mousePosition.subtract(this.transform.position).normalize();
24 let ray = Ray.Cast(this.scene, this.transform.position, dir);
25
26 if (ray)
27 {
28 // Canvas2d stroke APIs are unavailable under WebGL (scene.context is gl).
29 // Keep raycast for debug state; visual line omitted pending a GL line helper.
30 this.lastResult = ray;
31 }
32 }
33}