Old School LucasArts Inventory Selection

Hey guys, this isn’t a question on how to make an inventory system. I already have a simple one figured out from a previous project. I guess what I am really wondering is,
Does anyone have any ideas on how to go about adding, Look At, Pick Up, Push, Pull Etc.
Kinda like how the old Lucas Arts games used to work?
Actually even figuring “Pick Up.” is a great start for tonight.

What is bugging me about that is, You only want the “loot” to go into your inventory once the character is next to that object. Making the character walk to the destination shouldnt be overly hard to figure out, I’m thinking about taking a look at that code provided by Unity. They have one where a Bear walks wherever you click. But I’m not sure how to go about making sure he only picks it up when you click the “loot” and when he is near it. Any ideas to get my brain working would be great :wink: Sorry if this was worded weirdly.

Edit: I been thinking that, if you click on say “pickup” an invisible cube attached to the character enables, which has a script applied to it to add the loot to the inventory. And if you click on “look at” another invisible box enables. It would indeed work I think, but i’m not sure that’s the best method… what do you think?

A couple of approaches stand out to me. You could measure the distance between the player and the object in question, and only allow it to be transferred to inventory if the range is less than some threshold. If they click on it, and the range is outside of that threshold, then you move the player toward the object instead.

Another approach though I think is less viable due to more processing power required to do it, is to place a collider around the object that is larger than the object, and use that collider (set it to trigger) to detect when the player is within that zone. Then you can set some local flag on the object like “inZone” to true or false, depending if the collider trigger has entered or exited with the player. And when the player clicks on the object, it can check to see if it is inZone. I don’t like this idea because it adds extra collision detection which you need to keep minimal, so use the range instead if you can.

Regarding the rest of your question. It depends on how you implement the UI system. Will the user explicitly be required to click an icon (Look At, Pick Up, Walk To)? Or do you want an automatic system such that if it is far away, it defaults to Walk To, and if you’re close it defaults to Pick Up? In the former case, you just need a simple state machine to track the user’s preferred method of action based on their selection. Then when they click the object, you do that thing. In the latter, you would still just use the distance to determine if the object was in range and choose the best Action based on the range. For instance, a potion could be Walked to, then picked up, and a NPC could be walked to, then talked to.

In my game I’m using what the adventure game studio used to call hotspots, so if you want to pick up an apple and you have clicked “Pick up apple” the player will walk to the apple’s hotspot, which is a point on the screen that the player can pick up the apple from.

So you’d need something like:

if (player.transform.position == appleHotspot)
{
  // allow them to pick up the apple
}

Of course you only want that if you’ve clicked “pick up apple”, so you’d need something that disables that code if the user just happens to walk past it. If you want to be super fancy you could give the user the ability to change their minds. So if they click “pick up apple” but decide they don’t want to pick up the apple before the character has walked over there, then clicking somehow disables that code.

Some ways of doing something like this might either be a separate script attached to the object (like the apple) that is enabled and disabled when it can and cant be picked up. Or using coroutines, which would probably be great, but would take a bit of learning if youre not familiar with them.