# Interacting with things for first person horror game

**URL:** <https://forum.playcanvas.com/t/interacting-with-things-for-first-person-horror-game/28263>\
**Category:** Help & Support\
**Tags:** learning, scripting\
**Created:** [November 6, 2022, 3:29pm UTC](https://forum.playcanvas.com/t/interacting-with-things-for-first-person-horror-game/28263 "2022-11-06T15:29:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brent\_Reddick](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/brent_reddick/32/23835_2.png) [@Brent\_Reddick](https://forum.playcanvas.com/u/Brent_Reddick)\
**Post date:** [November 6, 2022, 3:29pm UTC](https://forum.playcanvas.com/t/interacting-with-things-for-first-person-horror-game/28263/1 "2022-11-06T15:29:19Z")

</div>

[https://playcanvas.com/project/1004154/overview/300-am-at-mr-greens](https://playcanvas.com/project/1004154/overview/300-am-at-mr-greens)

I want to make it where when I am near an entity I can press e to cause an event like pick up an item or open a passage. Any ideas or scripts would be helpful.

---

<div class="post-metadata">

**Author:** ![Tirk182](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/tirk182/32/21525_2.png) [@Tirk182](https://forum.playcanvas.com/u/Tirk182)\
**Post date:** [November 6, 2022, 3:47pm UTC](https://forum.playcanvas.com/t/interacting-with-things-for-first-person-horror-game/28263/2 "2022-11-06T15:47:01Z")

</div>

@Brent_Reddick I took a look at what you have so far and it looks great. I have made a little demo code to do this. Actually there are many ways and you can look at some more forum posts if you would like. Here is my example.

[https://playcanvas.com/project/939691/overview/spacedoors](https://playcanvas.com/project/939691/overview/spacedoors)

In fps-controller script I look for E

```javascript
// // Process Action keys
    if(app.keyboard.wasPressed(pc.KEY_E)) {
        
        this.processRaycast();
    }

```

Process a raycast

```javascript
FpsController.prototype.processRaycast = function() {
    var centerScreenX = this.app.graphicsDevice.width / 2;
    var centerScreenY = this.app.graphicsDevice.height / 2;

    var start = this.camera.camera.screenToWorld(centerScreenX, centerScreenY, this.camera.camera.nearClip);
    var end = this.camera.camera.screenToWorld(centerScreenX, centerScreenY, this.camera.camera.farClip);
    
    // raycast between the two points and return the closest hit result
    var result = this.app.systems.rigidbody.raycastFirst(start, end);

    if(result) {
        var pickEntity = result.entity;

        if(pickEntity !== null) {
            console.log(pickEntity.name);
            if(!result.entity.tags.has('double')) {
                // Execute Activation
                pickEntity.fire("activate");   
            }

        } else {
            console.log("Nothing Hit");
        }
        
    } else {
        
        console.log("Open Space and entity is NULL");
    }

};

```

I put listeners in the function for each item that has some type of action and then use the .fire to signal the action.
