Pickup item and use/place?

Vlaxep

Active member
I'm trying to figure out how to create an item that the Player can pickup, or begin a mission with, which when equipped is held in the hand/s
and the player looks at a specific place within a trigger perhaps, and places it in to position.

Doesn't need to be amazing, just hold the item by pickup/equip, move to where it needs to go, the either hit 'use' or 'fire' button or something like that, then the item gets placed, or disappears and activates the 'in place' item to visible state on the Prefab prop.

The premise is a 'Power Node' that requires player to find a 'SemiConductor', pick it up/equip it, go to the power node, then a prompt will display 'Place Semiconductor' > player hits 'F', 'E' what ever or 'fire' and it get's placed.

I can't animate so I was going to attempt using the 'Flashlight' animations (but there are none in ANimator controller????) ? Or any better suggestion? (The flashlight hand positions actually work quite well even when 'right click' is held, as the semiconductor is kind of briefcase sized.)

I semi-succesfully created the item to have in inventory, but I have no idea where to go from there to create a pickupable item, and then what mechanic/feature to use to allow the whole 'placement' thing....

Just looking for the simplest/best practice solution for this mechanic

Cheers
 
PS The way I want this Item to work is like a 'builder' style game where the object will show a 'hologram' style placeholder in a single specified place and then the 'actual' object being either spawned or just activated in place of the 'hologram'. Like a 'rust' or other base building type, but much simpler.

Also ideally I also want a hitscan or other method of checking whether the character is aiming/looking in a specified target area and is close enough to activate the 'placement' of the item.
 
For creating an item pickup to add an item to the player's inventory, you'll need to create an ItemPickup gameobject. There are several examples of this in the demo scene, as it's used for all the weapon pickups.

For that placement feature, you'd be best off creating a simple custom UsableItem. Flashlight.cs in the demo scene is a nice example of a simple custom UsableItem. So I imagine you'd want it to contain a reference to the transform of the hologram where the object will be placed, which can be shown whilst the item is active, then when the item is used (e.g. in the UseItem method), it spawns a prefab at that transform and disables the hologram.

Hopefully that's a good starting point, let us know how you get on.
 
Thanks @Andrew

I've been looking at how I can achieve this. Haven't looked at creating a pickup yet, just setting in inventory for now.

I've come up with this line of thinking:

- Item is 'shootable', but uses Flashlight animation on 'use', which I like the look of for my purpose
- Impact Layer will match only that of the 'PowerNode's trigger collider want to it to be able to Hitscan
- Hitscan Can interact with trigger

Now the probem I'm facing is what to do from here....

I'm thinking next step is to use the 'OnHitscanImpactEvent'

but I've got no idea how to target the Object Hit by the hitscan... or some other way to

(The 'PowerNode' object will be a prefab and there will be many in my scene. The player would be able to place the 'SemiConductor' item in any one of the 'PowerNodes' in the scene, so I need to only target the one the Character is looking/shooting at...)

My last idea on this is that I could use 'health' attribute, as before this Item can be placed, the 'PowerNode' will have to be at full health, or a specified amount.... Somehow could Hitscan and 'heal' the 'PowerNode' which I can then OnHealth = xxx or something like that - perform what I need to. I just don't get how to get a message to the Hitscanned object
 
Ok so I think I've solved this in a round about way...

I've set the 'SemiConductor_Item' up as a Shootable weapon. It fires a projectile on an isolated layer that only itself and the 'PowerNode' target are on. The 'Power node' then has a trigger collider which detects the Projectiles by it's 'tag', which I've also set the same name as the Layer for consistency.

Then upon detecting this trigger I can limit all actions to within this one prefab, as only the 'PowerNode' that detects a collision from a projectiles with this 'tag' will perform the appropriate actions. Phew, it's not ideal but I think it works.

(Having the projectiles visible for testing is great too, I'll make them faster, very short range, and invisible to create the effect, and gives me a better understanding and flexibilty of what's going on than hitscan - which I can't see how it works!)

I think I will create some kind of effect when holding the item so it kind of shows a holo-projection in look direction to prompt the player that they're needing to 'place' it somewhere.

I now have a strange problem to try fixing, dunno what's causing it but:

- Character now for some weird reason has all WASD input only moving forward...... Seems to be as a result of setting up this new item. As usual you solve one problem two more pop up ?
 
Last edited:
For your movement problem - whilst setting up your new item, did you change any of the character's abilities or state presets?
 
@Andrew I just managed to fix this by starting from scratch with the Item I created.I have no idea why or how but it fixed the problem. Cheers.
 
@Andrew I'm back tackling this problem again.

So I've got my 'placeable' object setup currently as a 'Shootable' but animated with Animator ID #42, so it behaves visually like the Flashlight, ie. at idle it's in player's hand down by their leg, and when 'aimed' it raises up in front of the character - I really like the look!

Problem I'm having is is need to a few things to be in place before the item is placed in the correct spot.

I've currently got a successful system in place where the Item fires the shootable projectiles and the collision is detected at the target object which in turn activates the same object in place.

The problem is I need the character to have a limited ammo (0, 1, or 2) of this object, and cannot be equipped when no 'ammo'.

So at this stage The player can 'fire' the projectiles when ever they like, so they could easily run out of ammo without aiming it at the target object.

I'm wondering can I create this effect somehow as Magic instead, which is still tricky because then I still need a way to manage inventory for the consumable?!?!

Any ideas on the best implementation? However it can be done the following is required:

• Target 'powernode' must detect a collision or some other combination of player 'looking' at/near target + being in range + having the item equipped and clicking 'use' input.
• On 'placement' the ItemSet will become 'unequipped' if ammo count goes to zero.

I will be creating a separate HUD area just for items/equipment like this 'placeable' object, so ideally I want to utilise the inbuilt ammo count in the Inventory component rather than managing it myself if possible, though still doable.
 
You could have your projectile refill the player's ammo if it doesn't collide with a target. But I still think that a custom UsableItem is more suited to your needs. All it would need to do is detect a trigger collider for the area it should work in and the extra specific functionality for your use case, like spawning the object, as I described in a previous post here
 
@Andrew it's not the end product I've been troubled with, just connecting the dots in between. But just spend the last 5 hours on a great solution along those lines, I think you were suggesting what I've done I just didn't quite know what you meant until now. So now I've got...

- Item that uses 'Flashlight' animation
- I use 'Fire2' which is AIM, to hold the item in front due to flashlight animation
- On 'HOLD Fire2 Input' a holographic projection of the same Item appears extended out from the object, it has a Trigger collider.
- The default colour is 'RED' for the holographic projected item AND the target placeholder on the wall
- Both the Projection and the TargetPlaceholder have the same tag and a trigger collider
- On collision the Projection disables it's mesh collider and the Target placeholder turns 'BLUE'
- On Exit or releasing AIM these conditions are reversed and Target Placeholder returns to RED

Worth noting I spent over an hour trying to figure out why this was working great with 3rd person Item but couldn't detect the collision on the First Person Item - ANSWER was that the 3rd person item was a child of the Character which is a rigidbody, whereas the FirstPerson item becomes a child of the Main Camera whch has no rigid body, so just had to add that in!

The next step is to implement the actual 'Fire1 Input' to place the item. I'm thinking it might be cleaner and less could go wrong if I manually update the Ammo for the item in the inventory.... Just wondering will that work? What I need to happen is that most likely the ammo count will be reducing to '0', so if I do this manually with the appropriate method, will the item automatically unequip? (I will have it set to Cannot Equip emplty)

Link to the result so far below.

 
If it's a ShootableWeapon and you have "Can Equip Empty Item" enabled, then I believe it'll get unequipped when you manually adjust the ammo amount. If not, you can simply check if the amount left is 0 and use the EquipUnequip ability.
 
Yep @Andrew this is now solved referring to my other thread which ties in to the way I've been trying to set up weapon/equipment mode and struggling with StartEquipUnequip.

Other thread if of use to anyone as this entire mechanic has been reliant and burdened with ItemSet issues: https://opsive.com/forum/index.php?threads/switch-between-two-sets-of-itemsets.4465/#post-22187

Final part of this will be to probably target the 'PowerNode' object and tell it that it can initiate the spawn/activation of the 'Physical' Semiconductor Object to show it has been 'placed'. I'll also have lights switch on to show it is now operating for effect!

Shouldn't be too difficult from here (famous last words)

Very excited to nearly have this in place!
 
Top