- Home /
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 ;) 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?
Answer by supernat · May 20, 2014 at 04:54 AM
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.
Thanks man, Just now I was kinda thinking along the lines of your second suggestion... it seems there might be a few ways to do it. Take a look at the "edit" I added in the question, tell me what you think... it seems like a painful way to do it that way though for every object. hmmmmm
Very interesting about the distance. Um yeah, I wanted the user to actually click on (look at, pick up)nothign automatically done. I love puzzle games
Wait I take that back, it's late here lolol. You are correct yes. If you already have "pick up" selected I would like him to walk over to it and pick it up.
I'm not sure I follow exactly the Edit in the question. I mean I would be doing everything with a static script. You don't need any particular game objects to attach the inventory scripts too (though you can do that if you want).
I would just use a set of static methods and static variables in an Inventory script to store and retrieve information about the inventory. And if you wanted to keep from destroying and re-creating meshes at runtime, you could have a GameObject attached to the player called "Inventory" that you parent the lootable items to when the player picks them up. That way, the items are all stored under a gameobject somewhere in the player hierarchy, but you would just disable their renderers, and then re-enable the renderer and unparent the loot, if they wanted for instance to place the object back on the ground in front of them.
haha my explaining is pretty bad I know. I think it deals with me not knowing exactly what I want to do with it. I'm gonna give your last suggestion a go just for the hell of it. I need some kinda starting point for trial and error. Thanks buddy! you got my brain turning either way :)
Answer by Romano · May 20, 2014 at 05:32 AM
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.
Your answer
Follow this Question
Related Questions
BurgZerg Arcade inventory system tutorials... Incomplete!! 1 Answer
Trouble working with a Custom class, JavaScript. 2 Answers
C# syntax seems fine, why wont yeild work? (Unsolved) 1 Answer
GUISkin is overlaying my button image 0 Answers
GUI.DragWindow causing Inventory Tooltip to stop showing 0 Answers