#Pick up and drop
73 messages · Page 1 of 1 (latest)
See PickupsDropsChilds example that's included with Mirror. Does exactly that.
I tried it and I don't understand it and can't make it work
I don't really have a drop item setup yet but for pickup and storing I simply have two scripts, ItemPickup and PlayerInventory
I simply use rayCast to get the Collectable Object and then destroy it on network after I add it to the SyncList in my PlayerInventory (You can use SyncDictionary).
And for the drop I guess just remove it from the PlayersInventory and Spawn it using NetworkServer.Spawn()
Make sure you mark your prefab as registered prefab
could you tell me like step-by-step how to set it up? Ik theres a site for it but its complicated and i dont really undersetand it
PickupsDropsChilds example is pretty simple, really. There's not that much code and it's heavily commented. Press 1/2/3 to show one of the objects in hand, press X to drop, click the dropped thing to pick it up again.
how do i change like the 1 2 3 inventory into a single item pick up and hold?
i dont know which scripts go where kinda
also in the network manager should i add anything tot he spawnable prefabs?
Just like the example, you need a prefab for the scene object for drops.
If you don't need to keep track of anything like ammo or similar for the dropped thing, you can just make an art prefab to show locally in hand, and a variant prefab for the dropped object that has a network identity on it.
so i teated the example, and it kind of works but doesnt, i cant pick up items but when i press 1, 2 or 3 they are always here and i can throw 2nd item away, press 2 and its here again and i can create infinite copies like this
click the items on ground to pick up
sure, that's just how the example is made - you don't have to have that part
oh alr
but still the pick up is very broken
should it be that way?
like i have to spam click to sometimes pick an item up but only like 1/4th of the items is pickable
It's really not - I can pickup every single item dropped
do you know what might cause this issue?
no idea. What version of Unity?
i put the script onto my player and setup everything like on the prefab and everything else i took from the prefabs
2022.3.60f1
unity version ^^
It's just this
void OnMouseDown()
{
NetworkClient.localPlayer.GetComponent<PickupsDropsChilds>().CmdPickupItem(gameObject);
}
maybe you have something else blocking the clicks?
obviously the scene object needs a collider of appropriate size
the capsule which the player has as a child
what do you mean by that?
i just copied it from the prefabs into the network manager as a spawnable prefab
can i raise the pick up range somewhere?
In the example the child art has a collider on it...that's required
i copied everything from the example so shouldnt it work?
im not really familiar with the english names, could you quickly explain what "child art" is? You seem to use it a lot and i have no idea what it is
can only assume its the child of a player
In the example, Ball, Bat, Box are art objects. They're instantiated as child art of the hand when held or as child of Scene Object prefab when spawned
Scene Object has a Rigidbody, and Ball, Bat, Box each have a correct collider
so prefab?
yeah i have them
wait
sceneobject has rigidbody?
yes, you can see that
nvm it does
i can pick up the items only when im walking on them and are lucky
but i managed to pick up every item
so every item is pickable but something is blocking
couldnt be the body of a player, right?
maybe its a low pick up range
collider is art prefab scaled too small?
not pick up range becasue i made my player really tiny and he still struggles
this is basic debugging, really - examine everything in the editor for correct scale
i think so
i made every collider twice as big as it should be and it worked perfectly
but doesnt work with the correct collider size
i set the collider size to 1.1 instead of 1 and no problem at all
should i just keep it that way?
all right its all bugged
i raised my player height back to normal and cant pick it up again
even with big colliders
it has to have big colliders and my player has to be short for it to work on my project
no idea what is happening
i guess something is wrong with my player
capsule has a hitbox and everything else is empty gameobjects
player has rigidbody