agmcleod Posted February 28, 2015 Share Posted February 28, 2015 Hello, so in a render loop, I am looping through all the objects that a laser can collide with, and perform an intersects mesh. This is only like 70ish objects total, so it's not entirely awful, but on my iPad mini i do notice some frame rate drops occasionally, so i'd like to improve it with octrees. Here's the code for the looping. This gets called in my render loop, after updating positions:GameScene.prototype.update = function (endScene) { this.player.update(); var enemies = this.wave.enemies; for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; endScene |= enemy.update(this.player); for (var l = this.lasers.length - 1; l >= 0; l--) { var laser = this.lasers[l]; if (enemy.mesh.intersectsMesh(laser.mesh, false)) { this.wave.removeEnemy(enemy); this.removeLaser(laser); } } } for (var i = this.lasers.length - 1; i >= 0; i--) { var laser = this.lasers[i]; laser.update(); for (var c = this.cubes.length - 1; c >= 0; c--) { var cube = this.cubes[c]; if (cube.intersectsMesh(laser.mesh, false)) { this.removeLaser(laser); } } for (var w = this.walls.length - 1; w >= 0; w--) { var wall = this.walls[w]; if (wall.intersectsMesh(laser.mesh, false)) { this.removeLaser(laser); } } }So yeah it's kinda gross. Using an octree instead, here's what i have:GameScene.prototype.update = function (endScene) { this.player.update(); var enemies = this.wave.enemies; for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; } for (var i = this.lasers.length - 1; i >= 0; i--) { var laser = this.lasers[i]; laser.update(); } var octree = this.scene.createOrUpdateSelectionOctree(); for (var i = this.lasers.length - 1; i >= 0; i--) { var laser = this.lasers[i]; var meshes = octree.intersects(laser.mesh.position, 1, false); for (var i = meshes.length - 1; i >= 0; i--) { var mesh = meshes.data[i]; if (mesh.name !== "ground" && mesh.name !== "player" && laser.mesh.intersectsMesh(mesh, false)) { console.log(mesh.position, laser.mesh.position); this.removeLaser(laser); if (mesh.name === "enemy") { this.wave.removeEnemy(mesh.refObject); } } } } return endScene;}The problem is, the data seems to return incorrect data. The laser intersects one of the cube objects, even though there should be none in range. Looking at the log, i see the mesh.position and laser.mesh.position have the same values. There something i missed here? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 28, 2015 Share Posted February 28, 2015 Hum sounds like it is correct at first glance Do you mind creating a playground to help me debug this? Quote Link to comment Share on other sites More sharing options...
agmcleod Posted February 28, 2015 Author Share Posted February 28, 2015 I can publish a version of the game with this if possible. Otherwise i feel like it would take me a while to set this up Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 2, 2015 Share Posted March 2, 2015 I agree but in this case please use babylon.max.js so that I can debug easily Quote Link to comment Share on other sites More sharing options...
agmcleod Posted March 4, 2015 Author Share Posted March 4, 2015 Hey delta, sorry just saw the reply. Here's a published version with the debug build: http://projects.agmprojects.com/wrath-test/. The update code i referred to use near the bottom of game_screen.js. After you click "Tap to start" and the countdown, use the mouse left button to shoot. It still spawns, but the mesh position and laser position equal the same value (in console log). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 5, 2015 Share Posted March 5, 2015 they are the same because laser.mesh and mesh are the same Quote Link to comment Share on other sites More sharing options...
agmcleod Posted March 5, 2015 Author Share Posted March 5, 2015 That would do it lol. Added some checks to ensure it doesnt pick other lasers GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.