Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayerPickUp items over the network #4

Merged
merged 3 commits into from
Oct 2, 2022

Conversation

Underewarrr
Copy link
Owner

@Underewarrr Underewarrr commented Oct 2, 2022

First we need to configure the object able to pick up and put this object in the world scene.
Create a new layer for pickup objects.
Sem título

Now we can create the script for the PickUp System called PlayerPickUp.cs.
Add the script to the player object

Sem título

We're going to start set up the project with NetworkBehavior scripts using the FishNet.Object
As usual, we are going to use OnStartClient() to be able to compare using the base.
Are few variables we need to set up before continue, first we want to have reference to the camera, also we want to know if we already have one object in our hand, also want to know what object we have in the hand, and we need a refence to the world obj Transform.
Sem título

First of all, we are going to configure the object holder from world objects.
Sem título

And we need to pass the camera refence to the main camera
With cam = Camera.main;
Now we make the KeyDown update

Sem título

Now in the new function PickUp we want to check where is the camera is look at.

Sem título

And we want to know the layer we are picked up the object.

Sem título

Now we pass to PickUp parameters.

Sem título

Here we want to check if we hold the object in our hand and take another object we want to drop the previous object, well to make that after creating the function we need to start configuring the server RPC.

Sem título

Let's create a Server RPC with a requiredOwnerShip.

Sem título

First we need to set if the object is in the hand, to do that we need to configure also the observer.
Sem título

Now we want to know what object we hit, we also want to know the position and the rotation from where we want to place it and what player has grabbed the object.

Sem título

And from the server we are going to set the object in hand for the observer.
Now in the player object we need to create a new layer for where should be the object when player pick.

Sem título

So now we can reference that into the script.

Sem título

And now we can set the object in hand server, and to this object we will give what object we are hiting and the pickup position, also the rotation for last we give that to the player.

Sem título

Now we have all this data, want to set the position of the object for the position we sent also for the rotation, also want sent the transform to the player.
If there is some collision we need to set the rigid body to is kinematic in the observer.
Sem título

After this we should be able to know what object we have on hand, also if we have and object in hand.
Sem título

Now we need to set the ray cast Distance in the editor.

Sem título

So now we want to have a drop button
Sem título

Now let's make a drop function First we need to see if we have an object in our hand, and we make the same for Server Rpc and Observer Rpc, this time we want to know which object is dropped we can take this information from Gameobject, and we want to know the transform of the world object.
Now we can drop the ObjectServer geting the object in hand to the Object world.
And once again we can make a check if the object have a RigidBody(Colision).
So if we have an object in hand, we want to drop first.
It is important in the drop function, we set the hasObjectInHand to false and the ObjectInHand to null.

Sem título

Remember to set the tag name in the worldObjects

Sem título

To be able to interact with the object we need to make sure network object are enabled

Sem título

Also, you can't forget to add a rigid body
Sem título

Also remember to set the pickup position in player object

Sem título

Player can take an object and drop.
Sem título
Sem título

@Underewarrr Underewarrr self-assigned this Oct 2, 2022
@Underewarrr Underewarrr merged commit 5fbdbf2 into master Oct 2, 2022
@Underewarrr Underewarrr added Status: Waiting for tests Feature need be tested Status: Working ✅ Working Feature labels Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting for tests Feature need be tested Status: Working ✅ Working Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants