NPC movement and dooractions

hey guys,



I want to add actions to the doors from the tutorial. That means that you can click on a door and something will happen. Any idea how to realize that?



Another question is how to realize random NPC movement?



Thanks for the help!



final

If you want to use the mouse to decide when to open the door, you should use picking (send a ray from the mouse pointer, and see if it collides with the door). There’s a tutorial for that, Hello Mouse Picking.



If you want a character to open the door, you should create a “Trigger” object. Basically a collision, or bounding box. See if it has collided with the character bounding box, and open the door.



Then you can have a timer on the door, and close it again after a certain time.



How random do you want the NPC to move? The simplest form would be to just randomize a direction, see if there’s anything in the way, and move there.

If you want it to behave somewhat rational, you should look into pathfinding. A* (“A-Star”) is a common method. Depending on your programming experience it can be a bit tricky to get your head around at first, but once you have, it’s quite easy. There are several threads about it on the forum, and plenty on the net, and there are several (including myself) who have posted snippets in the past.

That means i load for example a town scene into the game and than every door separately?

Yes, the doors need to be separate objects,