Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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?

1 decade ago by Joncom

What sort of built in functionality to do mean?

There is functionality to detect collisions between entities, yes.

Please be more specific.

1 decade ago by Shantred

I've assumed a little bit about logic and considered the following; Any object that would be interacted with would have to be created as an entity and that entity given the function that would run when accessed. After that, you'd bind a key for interaction (say spacebar) and when they hit that, depending on which way they are facing, see if there is an entity right in front of them and call that function. Am I in the ballpark here?

Also, how might you check for an entity right in front of you?

1 decade ago by Shantred

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.


I believe the post that I added right after yours gives a little more clarity. I'm looking more for the player is standing right next to another entity( say in this case a story-driven npc) and they hit a key and a dialogue box or other sort of interaction could occur

1 decade ago by Joncom

Here's a very simplified version of how you would do something like that.

/* 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.

                // }

            }

        }

    }

}

Edit - Typo.

1 decade ago by Shantred

Very helpful! Thank you. I'll fiddle around with this and see what I come up with.
Page 1 of 1
« first « previous next › last »