Hi Guys! I am new here ![]()
I have a simple question, searched for answer but with no success.
I have a torch and first person player that i am using (i am using first person prefab from AC if it matters)
Now, i need when interact with the torch (with hotspot in my example) to pick up the torch and equip it to my right hand.
Already do that by using "Character: Hold object function". Now i need to drop the item on the floor after pressing a button where comes the trouble. I tried to link hold object function to input (active in my case) and then if the condition is met (if i click the input button which i set in key input) to Object: Set parent clear function but nothing happens.
Can somebody tell me the full process of picking up the item -> and then after certain button is pressed dropping the item on the floor.
Thanks in advance!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @Jairus.
Are you looking to drop the item in a specific place, or wherever the Player happens to be standing? You may need some custom scripting in that case, in order to determine exactly where the item should be placed.
First, though, let's see about getting the Active Input working. It's not clear from your description if the issue is that the Active Input isn't being registered, or that the Actions in the ActionList aren't behaving as intended.
If you attach an ActionList: Comment Action to your Active Input's ActionList asset, you can type some words into it that will then appear in the Console window when it is run - you can look out for that to check if the ActionList is being run or not.
If it's not, check the way you've defined the Active Input. Be mindful that the Input button field corresponds to the name of the Input as listed in Unity's Input Manager, i.e. "Fire", "Jump" etc - and not the name of the key it's actually mapped to, i.e. "x" or "mouse 0".
If it's not clear what's wrong, share some screenshots of your Active Inputs window, Unity's Input Manager settings, and the ActionList it's set to run - and we'll take a look see what the issue might be.
Hi Chris! Thanks for the fast response! For the beginning i just want to drop the item in the area where player stands after using a button/. Here is my configuration. My input button is working properly, but when i click "q" nothing happens.
https://imgur.com/a/rityFH4
Does the torch have a Rigidbody and collider (if you want it to drop on the floor)?
I have collider. Tried to add rigidbody on the torch mesh (and enable kinematic to stay still) but when i pick it up and click "q" nothing happens again.
I need to see your Active Inputs window - and ideally the ActionList that you've mapped to the Active Input.
The screenshot you've shared is all part of the Torch's interaction - but it doesn't look like that's set up correctly.
In this list, you're parenting the torch to the Player's hand, but then disabling the active input (because New state is unchecked), and then clearing the parent of the Player itself.
To detach the torch from the Player's hand, you'll need to have such an Action with Is Player? unchecked - it's the Torch you want to affect, not the Player - and the Torch as the object to parent. So long as the Method is set to Clear Parent, it will unparent the Torch from whatever it's parented to.
But, you'd want this Action to be part of the Active Input's ActionList - not the Interaction. Otherwise, you'll parent the torch to the player and then immediately un-parent it.
More may be necessary to get the torch falling onto the floor - i.e. to control the Rigidbody's Kinematic state when dropped/picked up - but let's get the parenting/unparenting working first.
Thanks Chris! I am sorry that I am not that general. Let me try:
Yesterday I managed to pick up my torch and then on Active button "Q" drop it using this settings:
Please, tell me first is that a good way of doing this:
ActiveInput DropItem list: https://imgur.com/a/Jyuhx9T
ActiveInput actionList: https://imgur.com/a/EYKgOe4
Torch actionList:https://imgur.com/a/2GMj5DP
Torch_prefab: https://imgur.com/a/ur0LuB3
Ok. Now I have a torch that I equip after click on the hotspot and the torch is going to my righthand prefab in my game hierarchy: https://imgur.com/a/AZtfltI
My second problem is: When my kinematic is true on my torch_mesh rigidbody when I drop item using "q" it stays in the air (no-surprise)
But more weird thing is that when i uncheck my kinematic tick in the torch_mesh, when I pick up the torch, the mesh is getting bugged afterwards and disappears underground almost immediately like this:
https://imgur.com/a/lBa9zg9
I need the torch to be stable in my player hand and not float like this.
I tried lift up the gameobject "righthand" but no change happens.
What if you actually just have the torch in the player's hand all the time, but disabled, and just enable it when you "pick it up" (even though you're not _really _picking it up). Then, just remove the dropped version from the scene at the same time.
Hi Deckhard. This is good solution, but my concern is what if i need to pick up another item?
I was thinking if I enable kinematic after i pick up the torch, and then on Drop function i disable it. Is this a good aproach?
Sure, it's just that relying on physics can be unpredictable.
Maybe an alternative would be to add every item that you can pick up as a child of the character's hand and enable them when needed, then instantiate a rigid body version when dropping them. Remove that same added object from the scene when picking it up.
I'm not sure on the specifics of your game though, whether there could be many different identical objects, whether they are used in different scenes etc as they would need to have Constant IDs in order to be used by action list assets. I do not know why there is a problem with the disappearing object though or floating etc. Hopefully Chris can shed some light on that tomorrow.
The approach looks fine, but I notice a couple of things:
1) You're enabling the Torch Hotspot in its Use interaction - should it instead disable it?
2) You're not disabling the Active Input in the ActionList_Drop asset, so repeated presses would cause it to run even when the Torch is no longer held
You could do this with a simple script, but likely you can also rely on animation.
IIRC, you can use Animation to control the Torch's Is Kinematic property. You could then use AC's Object: Animate Action to play a "Kinematic On" animation when you pick it up, and "Kinematic Off" animation when you drop it.
The steps involved would be:
Give it a go and let's see how things fare - I can advise on a code-based approach if necessary.
This is a good point. There's a lot more to any given feature than just it working "in the moment". Things like scene transitions, multiple instances of the same object, save game data etc all factor into what approach you take. It really depends on what system you want exactly for this, but the above should work for the single situation you're asking about.
Thank you! I am enabling the torch hotspot, because i need to be able to pick it again if i drop it. My game will be open world exploration puzzle adventure game, with no combat mechanics.
I have some issues trying to implement this way using animations. Let me show u my progress ->
Animation - Kinematic_ON: https://imgur.com/a/qP4ohaV
Animation - Kinematic_OFF https://imgur.com/a/lBVwHms
Controller: https://imgur.com/a/i6nTca8
The last part to update the kinematic state i did not understand. When i apply Object: Animate https://imgur.com/a/QH7hyuF I am not sure what to check here to make the transition.
Thank you for your patience
For the Method field I would use a Parameter change rather than Play Custom - this will allow you to manipulate the parameters in the animator controller rather than just play animations directly. I am not familiar with the Legacy animation system though, only Mecanim (or whatever they call it these days).
Also, make sure the Has Exit Time? is not ticked on the transition between the states, otherwise it will automatically change between states when the animation finishes.
In that case, it's probably best to do this in the ActionList that drops the torch, so that it is not inadvertently selectable while being held.
To update an Animator, set the Action's Animation engine to Mecanim. "Mecanim" was the name Unity used to tout the Animator system way back when.
You'll then want to set the Method field to Change Parameter Value, Animator to your Torch prefab, Parameter to affect to IsKinematic, and then check/uncheck the Set as value box as necessary.
As Deckard_89 points out, you'll also want to make sure Has Exit Time is unchecked in your Animator's Transitions - otherwise it'll wait until the animation has finished before the parameter change has any effect.
Hi and thanks for the great support. I was able to make the functionality I need.
Now, after dropping the torch (after pressing the hotkey and changing the kinematic property from true to false i have four problems.
1.There is a little gap (1 second) after pressing the drop hotkey and before the torch starts to drop (it stays in the air for like 1 second, but feels unnatural)
2.Then, 90 % of the times the torch sinks underground. The torch_mesh has rigidbody and mesh collider
3.When my torch_prefab stay on the terrain (don't sink underground) the hotspot goes way of and i cannot click on the torch_prefab again.
(I parent the hotspot with the torch_prefab to stay on it)
(I think the hotspot stays on the level where i drop the torch, not where it falls)
I uncheck the "has exit time" property, then i add new action in my drop_list right after my first action which is (0:Object:Set parent - clear parent) which enable the hotspot.
Here is my setup till now:
Drop_Actlionlist - https://imgur.com/a/R3powxn
Torch_Actionlist - https://imgur.com/a/2T4DnvH
Here is the video showing all problems in one "pick up -> drop -> pick up -> drop cycle"
https://imgur.com/a/YS13n47
First time on picking it up it shows no problem. I parent the torch in my hand at the desired position. Then on pressing q to drop the torch u can see 1 seconds before actual dropping and when the torch is on the ground i found the hotspot to be the level where i drop the torch, not in the ground. And then, on the second pick up, my torch did not correctly goes in my hand. Then on the last drop it goes underground. (I know the torch sinks now because it was underground anyway when i drop it but it sinks regardless the position in my hand. Most of the times sinks underground even if it is correctly parented and it's way above the ground)
Thanks!
I still see the issue in your Drop_ActionList that you're not disabling the Active Input, so repeated presses would cause it to run even when the Torch is no longer held.
The main issue I'm seeing is that your Rigidbody is not on the Torch's root object - I expect it's on the Torch_mesh object, which is a child alongside the Hotspot. This means that the position of the Hotspot is independent of its perceived position (the visible mesh).
You need to make sure that the Rigidbody and Animator are both on the root object, so that the Hotspot is always a child of the Rigidbody, and always moves with it.
Given that your Torch prefab's root has no components on it, the easiest way to do this would probably be to simply:
You'll have to re-connect the new Torch prefab to your Object: Set parent Actions, but you should get better behaviour then.
The going-through-the-floor issue is going to be related to Unity's physics settings, as AC won't be involved. But let's get the above issue sorted first and see how things fare then.
Hi Chris! We are getting closer to the functionality i need!
I fixed this stuff and now I can pick up and drop my torch prefab and it goes to the right hand position every time!
Also, the hotspot position is very accurate! Thansk!
Now, my last two major problems are:
After pressing dropkey it has 1 second delay before actual action of dropping the torch (The torch stays in the air 1 second before starts to drop)
)
I assume that is how "clear parent" work (maybe we can add some pushforce or something?
And the second major problem is that my torch continues to sink underground and I cannot find why.
I am using terrain with collider, my torch has also mesh collider.
Thanks in advance!
It's hard to tell in the video when you press the key vs when it drops. Keep your Rigidbody Inspector open at runtime - does the "Is Kinematic" property change its value at the moment you press the key?
If so, it may be a collision issue with the player. You can try walking backwards at the time to confirm this.
If not, it may be an animation issue - check that you have no "Has Exit Time" fields still checked in your transitions.
This is a Unity issue, and will be a case of playing with your physics and Rigidbody settings.
See Unity's docs and forum for resources on how to improve this, but things in particular to focus on will be ensuring you have a convex collider (or a Box Collider), Continuous collision detection, and an appropriate "Solver Iterations" value in your Physics settings.
Hey Chris! Thanks for the patience and showing me the right way of doing the thigs!!! U guys are awesome!
I manage to fix the sink underground problem after changing the mesh collider with a box collider (for now at least)
Now, i have one pretty nice function for picking and dropping items.
My last question related to this topic (at least for now) is:
I assume that i would need to make inventory for picking up the items and every time I pick item from the ground it would be with the same steps that i made now for creating this functionality.
I need to be able to drop the current item in the hand if i pick another one.
Also, is it possible to pick the item only after one click to the hotspot?
Now i need to click one time to mark the hotspot and second time to pick it up.
My main idea is to make first person puzzle exploration game that my main player would be able to carry one item in the hand and more items in the inventory.
But i need to make sure that i would be able to pick only one item in my hands.
What are the "steps" from now on?
Thanks !
)
If you want to swap the currently-held item for another, as opposed to preventing the other one from being pick-up-able, you can just run the ActiveInput_Drop ActionList before running any other Actions in your "Pick up" Interaction. This would be a case of inserting an ActionList: Run Action at the top of your Interaction ActionList.
Though, that would only work if you were carrying the Torch and not some other item - since your ActiveInput_Drop ActionList references the Torch directly, so will only ever affect that.
To extend this system to multiple items, you'd need to have a way of knowing which item you want to drop. You could try using Variables to keep track of what you're holding, but it wouldn't scale so well if you have many items, or many instances of the same item type.
Instead, you can look into the use of ActionList parameters. These are a way of modifying Action fields at runtime. So for example, an Object: Set parent Action's Object to affect field could be dynamic, and set to whatever object you want to affect at the moment you run it.
A tutorial on this concept can be found here, and details can also be found in the Manual's "ActionList parameters" chapter.
What you'd want to look at is using GameObject parameter(s) to control which objects are affected by the Actions in your ActiveInput_Drop ActionList. If you can first make sure that the three Actions you have in there all reference the same object, it'll be a lot easier. See if you can make sure the Torch's Hotspot and Animator can be placed on the prefab's root - that way, you only need to rely on one GameObject parameter to override all three Actions.
Then, when you pick up the Torch, you can set this GameObject parameter value to the Torch. This can be done with the ActionList: Set parameter Action.
What are your "Interface settings" in your Settings Manager set to? If your Interaction method is set to Context Sensitive, Hotspot interactions should just be a case of single-clicking either the left-mouse button, or pressing an input named InteractionA.
Hi Chris! Thanks for the heads up! I was able to read the manual and the tutorial u gave me, but maybe it will take a little while before i understand this concept at 100 %
I made a 3 parameters in my actionlist_drop list and assign them to the action list itself. It behave exactly the same.
Actionlist_Drop - https://imgur.com/a/azn7J3z
parameters - https://imgur.com/a/bhL5Rir
What functionality provide me this? Can i pick up another item now with this setup, or i will need to make another action lists?
Do i need to make the same parameters for "torch use" actionlist and apply it with "set parameter action" to the new items that i want to put in the game?
(Ignore that i am not disabling the action input in my drop list, i will fix that later)
Thanks!