Skip to content

Commit

Permalink
Trying to better Hands
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoRean committed Sep 23, 2023
1 parent fd84cb2 commit c741f5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
33 changes: 28 additions & 5 deletions monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,35 @@ class Monsters {
if(this.rayhelper !== undefined){
this.rayhelper.dispose();
}
if (this.monsterList[i].torched <= 0 ) {
var handDistance = BABYLON.Vector3.Distance(this.monsterList[i].hands.absolutePosition, this.player.getTorsoPosition());
if (handDistance < 1) {
this.happyMonster(i);
this.player.loseOneLife();

if (this.monsterList[i].torched <= 0 ) {
var inSightInfo = isInPossibleSight(this.monsterList[i].hands, this.player.getTorsoPosition(),
new BABYLON.Vector3(0,0,1), Math.cos(Math.PI/2), false);
if(inSightInfo.inSight){
var dir = this.player.getTorsoPosition().subtract(this.monsterList[i].hands.absolutePosition);
var ray = new BABYLON.Ray(this.monsterList[i].hands.absolutePosition, dir, 1);
var hits = scene.multiPickWithRay(ray);

if (true){
if (rayHelper !== undefined)
rayHelper.dispose();
rayHelper = new BABYLON.RayHelper(ray);
rayHelper.show(scene);
}

if (hits){
hits = sortPickedMeshesByDistance(hits, 0);
for (var i = hits.length -1; i >= 0; i--) {
if(this.player.model == hits[i].pickedMesh){
if(hits[i].distance < 1)
this.happyMonster(i);
this.player.loseOneLife();
}else if (this.getExcusedMeshes().includes(hits[i].pickedMesh)){
}else{
break;
}
}
}
}
//Vedo la bambina? -> vado da lei?
else if (this.canSeeGirl(i)) {
Expand Down
8 changes: 6 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ function isInCloseSight(observer, lookedAt, excused, distance, adjustHeight = nu
}
var rayHelper;
// method that checks if, given two objects and a forward direction of the observer, the lookedAt is in possible sight
function isInPossibleSight(observer, lookedAt, forward, targetCos){
function isInPossibleSight(observer, lookedAt, forward, targetCos, mesh = true){

var direction = directionFrom(forward, observer);
var vecFrom = BABYLON.Vector3.Normalize(lookedAt.absolutePosition.subtract(observer.absolutePosition));
if (mesh){
var vecFrom = BABYLON.Vector3.Normalize(lookedAt.absolutePosition.subtract(observer.absolutePosition));
}else{
var vecFrom = BABYLON.Vector3.Normalize(lookedAt.subtract(observer.absolutePosition));
}
var cos = cosBetween(direction, vecFrom);

var inS = false;
Expand Down

0 comments on commit c741f5e

Please sign in to comment.