1 decade ago by Shantred
Is there built-in functionality to interact with objects and enemies? I can't find anything in the class documentation. Is there some sort of raycasting support or another method that I've missed?
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
Quote from Joncom
What sort of built in functionality to do mean?
There is functionality to detect collisions between entities, yes.
Please be more specific.
/* main.js */ init: function() { // Bind keys. ig.input.bind( ig.KEY.SPACE, 'interact' ); } /* player.js */ update: function() { this.parent(); if( ig.input.pressed('interact') ) { // Loop through all entities which are // considered to be interactable. // Let's say only enemy.js can be // interacted with, then: var enemies = ig.game.getEntitiesByType(EntityEnemy); // Found some? if( enemies ) { for( var i = 0; i < enemies.length; i++ ) { // Check each enemies[i].pos.x and y // value relative to the player // to determine if proximity // is close enough to interact. // And if it is... // { // Perform interaction, // whatever that might be. // } } } } }