For anyone struggling to figure out how to reference another script, I used a video by Game Dev Beginner "How to get a variable from another script in Unity (the right way)" to figure it out. Thank you Jon for this helpful tutorial.
hey I'm a beginner can. I watched the vid but I'm still confused on how to properly reference a script with in another? Can you tell me what code you put?
@@ItsJustAngelYT I will try my best to remember what I did to the best of my ability. This won't be something you will be able to simply copy & paste: 1. first, in your FPS/Player controller script, you want to make the variables that control the mouse sensitivity is public, e.g. public float lookSpeedX = 2.0f; public float lookSpeedY = 2.0f; 2. Second, make whatever function that moves your camera is also Public, e.g. public void HandleMouseLook() 3. From here on we will make our way back to our PickUPScript, and similar to what the end of this video demonstrates, you want to declare the FPS controller script at the bottom of the section of the PickUpScript where you have declared your other public/private floats and bool variables. This is just telling the system that another script is going to be referenced. Simply call the script you want to reference and assign it a name. e.g. FPSController mouseLookScript; "FPSController" is the script I am referencing, and mouseLookScript is the name I have given it to declare it. 4. Now go to Void Start(), use the named variable we are going to use to reference the FPS controller, e.g. void Start() { LayerNumber = LayerMask.NameToLayer("holdLayer"); mouseLookScript = player.GetComponent(); } The variable we gave a name to will now be able to call the FPSController script we are using for our intended purposes. The section of this line that uses the "" characters is annotating what script we are referencing when called. 5. Now go below into our Void RotateObject() function, and inside the IF statement that calls for our rotate object input, use the reference variable we created to call the variables we made public earlier that controls the mouse sensitivity, e.g. if (Input.GetKey(KeyCode.Mouse2)) { canDrop = false; //disable player being able to look around mouseLookScript.lookSpeedX = 0f; mouseLookScript.lookSpeedY = 0f; Here we are calling the variable we created to reference the fpsController script, and we are calling the variable from our fpsController that controls our camera sensitivity. the reason why we are setting both lines to 0 is because this is where we are freezing the camera when we press our desired input (I set mine to Mouse2/middle mouse button). 6. Now we go below to our else command where our "canDrop" command is and type the same lines we just used above, e.g. else { //re-enable player being able to look around mouseLookScript.lookSpeedX = 2.0f; mouseLookScript.lookSpeedY = 2.0f; canDrop = true; } Just make sure to type the default camera sensitivity value is the same as the fpsController script we are referencing, which will re-enable the camera to move. That is all I can remember off the top of my head, hope this helps. I'm sure there is a better way of doing this, but I'm still an amateur. The Fps controller I am using is based on code created by Comp-3 Interactive.
For anyone else who has trouble with this: 1. Make sure to either name everything the same as Jon does or to rename them in the script file to what you've used. 2. By default the keys are 'E' to pick up/drop, hold 'R' and move mouse to rotate, and 'Left Click' to throw. This can be changed in the script. 3. Make sure the object you're picking up has a box collider and a rigidbody component. 4. Make sure on your camera (where you added the script) that 'Player' is set to the parent file of your camera movement. Hopefully, that helps some of you out. But if you're still stuck don't bother asking me for help. I just started learning Unity today, so idk lol.
Great work, thanks for explain how to rotate an object! For those in the future, i did it this way: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Interactor : MonoBehaviour { public GameObject player; public Transform holdPosition; //if you copy from below this point, you are legally required to like the video public float throwForce = 500f; //force at which the object is thrown at public float pickUpRange = 5f; //how far the player can pickup the object from private float rotationSensitivity = 1f; //how fast/slow the object is rotated in relation to mouse movement private GameObject heldObj; //object which we pick up private Rigidbody heldObjRb; //rigidbody of object we pick up private bool canDrop = true; //this is needed so we don't throw/drop object when rotating the object private int LayerNumber; //layer index private PlayerMovement playerMovement; //Reference to script which includes mouse movement of player (looking around) //we want to disable the player looking around when rotating the object //example below //MouseLookScript mouseLookScript; void Start() { LayerNumber = LayerMask.NameToLayer("holdLayer"); //if your holdLayer is named differently make sure to change this "" playerMovement = player.GetComponent(); //mouseLookScript = player.GetComponent(); } void Update() { if (Input.GetKeyDown(KeyCode.E)) //change E to whichever key you want to press to pick up { if (heldObj == null) //if currently not holding anything { //perform raycast to check if player is looking at object within pickuprange RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, pickUpRange)) { //make sure pickup tag is attached if (hit.transform.gameObject.tag == "canPickUp") { //pass in object hit into the PickUpObject function PickUpObject(hit.transform.gameObject); } } } else { if(canDrop == true) { StopClipping(); //prevents object from clipping through walls DropObject(); } } } if (heldObj != null) //if player is holding object { MoveObject(); //keep object position at holdPosition RotateObject(); if (Input.GetKeyDown(KeyCode.Mouse0) && canDrop == true) //Mous0 (leftclick) is used to throw, change this if you want another button to be used) { StopClipping(); ThrowObject(); } } } void PickUpObject(GameObject pickUpObj) { if (pickUpObj.GetComponent()) //make sure the object has a RigidBody { heldObj = pickUpObj; //assign heldObj to the object that was hit by the raycast (no longer == null) heldObjRb = pickUpObj.GetComponent(); //assign Rigidbody heldObjRb.isKinematic = true; heldObjRb.transform.parent = holdPosition.transform; //parent object to holdpositionition heldObj.layer = LayerNumber; //change the object layer to the holdLayer //make sure object doesnt collide with player, it can cause weird bugs Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), true); } } void DropObject() { //re-enable collision with player Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), false); heldObj.layer = 0; //object assigned back to default layer heldObjRb.isKinematic = false; heldObj.transform.parent = null; //unparent object heldObj = null; //undefine game object } void MoveObject() { //keep object position the same as the holdPositionition position heldObj.transform.position = holdPosition.transform.position; } void RotateObject() { if (Input.GetKey(KeyCode.R)) { canDrop = false; playerMovement.enabled = false; // Desativa o script para bloquear o movimento e olhar float XaxisRotation = Input.GetAxis("Mouse X") * rotationSensitivity; float YaxisRotation = Input.GetAxis("Mouse Y") * rotationSensitivity; heldObj.transform.Rotate(Vector3.down, XaxisRotation, Space.World); heldObj.transform.Rotate(Vector3.right, YaxisRotation, Space.World); } else { playerMovement.enabled = true; // Reativa o script canDrop = true; } } void ThrowObject() { //same as drop function, but add force to object before undefining it Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), false); heldObj.layer = 0; heldObjRb.isKinematic = false; heldObj.transform.parent = null; heldObjRb.AddForce(transform.forward * throwForce); heldObj = null; } void StopClipping() //function only called when dropping/throwing { var clipRange = Vector3.Distance(heldObj.transform.position, transform.position); //distance from holdPosition to the camera //have to use RaycastAll as object blocks raycast in center screen //RaycastAll returns array of all colliders hit within the cliprange RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, transform.TransformDirection(Vector3.forward), clipRange); //if the array length is greater than 1, meaning it has hit more than just the object we are carrying if (hits.Length > 1) { //change object position to camera position heldObj.transform.position = transform.position + new Vector3(0f, -0.5f, 0f); //offset slightly downward to stop object dropping above player //if your player is small, change the -0.5f to a smaller number (in magnitude) ie: -0.1f } } }
Is there any way to include a text which tells what is the button to pick up the object. I have no idea where to put it since the pickup range is after the getkeydown. This would really help!
Hi! Yes that is definitely possible. You should add a canvas gameobject to the workspace, and add a text object to it. Then you can detect whenever a player mouses over the object you want to pick up by raycasting, checking if it hits the object. If it does hit the object, get it's position and use it to set the position of the text, you will then have to convert the coords from worldspace to screenspace. Then set the text of your canvas object to something like "Press E to pick up". If the raycast is not hitting any pick up objects then make sure the text is set to empty "". So basically all you are doing is placing a UI object in your 3D space, moving it around from object to object and changing the text. Look up some guides on 3D UI elements if you are struggling, best of luck :)
This is for anyone who wants to rotate the object to world space! Replace this: heldObj.transform.Rotate(Vector3.down, XaxisRotation); heldObj.transform.Rotate(Vector3.right, YaxisRotation); With this: heldObj.transform.Rotate(Vector3.down, XaxisRotation, Space.World); heldObj.transform.Rotate(Vector3.right, YaxisRotation, Space.World); Hope this helps! 🧀🧀
hi! thank you so much for the tutorial! i'm a bit confused on how to lock the background lookaround rotation while you're rotating the item. could you advise on this? thanks!
Great video, but I do have one problem. Every time I try to pick up the sphere I want to pick up, nothing happens. I have it on the right tag, but on the default layer. When I try to put it on the Hold layer, it can be seen through walls. Any way these can be fixed?
Hello, great tutorial. I will definitely use it in the future! One concern I do have is if your rendering the object above everything, doesn't that mean that you can see it through walls? Sorry if the answers obvious but I haven't used this system yet. Thanks
Hey thanks for the nice comment. The layer gets rendered above everything, and since we only assign the object to that layer when we are holding it, the object doesn't appear through walls when it is on the ground.
I loved your tutorial and script it's so useful and great. But i've a question: I want my pickable objects to be affected by my post process which is in my main camera object. How can i do that?
when I make the same settings in both of my cameras I think my unity only uses one camera and that is the pickupcamera in my unity everything goes black other than the objects in holdlayer. how can I fix it
@@jondevtutorials4787 yes I was using it and I turned it off and now I have them. But there is another issue with the code. When I pick up a cube for example and look around the cube changes its scale. Why is this happening?
@@jondevtutorials4787 I'm facing a weird issue sometimes when I throw an object, it doesn't always gets thrown forward. sometimes towards the player itself.
@@HiHoSHOW perhaps the player is blocking, try changing the point where it is being thrown from. Else check how direction is being calculated in the addforce method, perhaps you are using worldspace not local space.
Hi, i knwo this video is old but i'm trying to use your code. I have a weird problem. When i pick up an object his scale changes. Making more big or more little. Any idea whats happening?
I don't know if it's still relevant, but if the size of the Player model is different, this happens. So, if you set the player transform to 1,1,1, it will be fine. (It helped me)
Great tutorial! I've implemented the script and managed to get it working. But when I pick up and throw the object, the scaling of the object change. How can i fix this. And my camera also rotates when rotating the object, is there any way to fix that?
This tutorial isnt working for me. It might be because I dont know how to reference my FPS script, but none of this actually works for me, man. Its always these seemingly easy tutorials that are the most complex. Or maybe im just stupid
I was getting the same error. I fixed it by making sure my hold layer was labeled 'holdLayer' exactly like in the script. Alternatively you could change the script to match whatever you named your hold layer.
Hey, awesome video. I have a problem when picking up the item. I have a post process volume on my main camera, but when I pick up the item the effect doesn't apply onto the item until I drop it. I tried putting a volume on the other camera also, but it doesn't work still. Solutions?? Edit: Also, it clips through the map frequently.
Post process effects act on layers, you should have the option to select/add layers in the inspector for the post processing effect. As for the fact that it clips through the map, I think there is a StopClipping() func. that you may want to look at which tries to stop the the object from being placed through colliders. It's at the very bottom of the code, try editing the last few lines to your spec.
Unsure if you're still responding to comments or not but I have a slight problem. Picking up items is fine at first but for some reason after a bit it is a pain to pick up items. There's like a 90% chance the object cant be picked up and it gets very annoying. Any fixes? I'm using mesh colliders if that helps!
can someone help me.., it doesnt work?? edit : i use urp and some things change with the camera. but i dont know why i cant pick up the object. i already assigned the tags and all the stuff, checked several times and i dont seem to find the problem why. 2nd edit = i figured it out, turns out it needed rigidbody. but now the object is invisible when its picked up. any solution??
For anyone struggling to figure out how to reference another script, I used a video by Game Dev Beginner "How to get a variable from another script in Unity (the right way)" to figure it out.
Thank you Jon for this helpful tutorial.
hey I'm a beginner can. I watched the vid but I'm still confused on how to properly reference a script with in another? Can you tell me what code you put?
@@ItsJustAngelYT I will try my best to remember what I did to the best of my ability. This won't be something you will be able to simply copy & paste:
1. first, in your FPS/Player controller script, you want to make the variables that control the mouse sensitivity is public,
e.g.
public float lookSpeedX = 2.0f;
public float lookSpeedY = 2.0f;
2. Second, make whatever function that moves your camera is also Public,
e.g.
public void HandleMouseLook()
3. From here on we will make our way back to our PickUPScript, and similar to what the end of this video demonstrates, you want to declare the FPS controller script at the bottom of the section of the PickUpScript where you have declared your other public/private floats and bool variables.
This is just telling the system that another script is going to be referenced.
Simply call the script you want to reference and assign it a name.
e.g.
FPSController mouseLookScript;
"FPSController" is the script I am referencing, and mouseLookScript is the name I have given it to declare it.
4. Now go to Void Start(), use the named variable we are going to use to reference the FPS controller,
e.g.
void Start()
{
LayerNumber = LayerMask.NameToLayer("holdLayer");
mouseLookScript = player.GetComponent();
}
The variable we gave a name to will now be able to call the FPSController script we are using for our intended purposes. The section of this line that uses the "" characters is annotating what script we are referencing when called.
5. Now go below into our Void RotateObject() function, and inside the IF statement that calls for our rotate object input, use the reference variable we created to call the variables we made public earlier that controls the mouse sensitivity,
e.g.
if (Input.GetKey(KeyCode.Mouse2))
{
canDrop = false;
//disable player being able to look around
mouseLookScript.lookSpeedX = 0f;
mouseLookScript.lookSpeedY = 0f;
Here we are calling the variable we created to reference the fpsController script, and we are calling the variable from our fpsController that controls our camera sensitivity.
the reason why we are setting both lines to 0 is because this is where we are freezing the camera when we press our desired input (I set mine to Mouse2/middle mouse button).
6. Now we go below to our else command where our "canDrop" command is and type the same lines we just used above,
e.g.
else
{
//re-enable player being able to look around
mouseLookScript.lookSpeedX = 2.0f;
mouseLookScript.lookSpeedY = 2.0f;
canDrop = true;
}
Just make sure to type the default camera sensitivity value is the same as the fpsController script we are referencing, which will re-enable the camera to move.
That is all I can remember off the top of my head, hope this helps. I'm sure there is a better way of doing this, but I'm still an amateur.
The Fps controller I am using is based on code created by Comp-3 Interactive.
What code did you use?
For anyone else who has trouble with this:
1. Make sure to either name everything the same as Jon does or to rename them in the script file to what you've used.
2. By default the keys are 'E' to pick up/drop, hold 'R' and move mouse to rotate, and 'Left Click' to throw. This can be changed in the script.
3. Make sure the object you're picking up has a box collider and a rigidbody component.
4. Make sure on your camera (where you added the script) that 'Player' is set to the parent file of your camera movement.
Hopefully, that helps some of you out. But if you're still stuck don't bother asking me for help. I just started learning Unity today, so idk lol.
You are amazing thank you !!!!.
i can get it a try
Sorry but how does this video only have 60 views when its the best method of doing this I've found
Thanks!
I loved it completely, and the memes sajkdsakljd so good, hope to see more of your tutorials soon!
Loved the tutorial, keep up the good work
Great work, thanks for explain how to rotate an object!
For those in the future, i did it this way:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interactor : MonoBehaviour
{
public GameObject player;
public Transform holdPosition;
//if you copy from below this point, you are legally required to like the video
public float throwForce = 500f; //force at which the object is thrown at
public float pickUpRange = 5f; //how far the player can pickup the object from
private float rotationSensitivity = 1f; //how fast/slow the object is rotated in relation to mouse movement
private GameObject heldObj; //object which we pick up
private Rigidbody heldObjRb; //rigidbody of object we pick up
private bool canDrop = true; //this is needed so we don't throw/drop object when rotating the object
private int LayerNumber; //layer index
private PlayerMovement playerMovement;
//Reference to script which includes mouse movement of player (looking around)
//we want to disable the player looking around when rotating the object
//example below
//MouseLookScript mouseLookScript;
void Start()
{
LayerNumber = LayerMask.NameToLayer("holdLayer"); //if your holdLayer is named differently make sure to change this ""
playerMovement = player.GetComponent();
//mouseLookScript = player.GetComponent();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E)) //change E to whichever key you want to press to pick up
{
if (heldObj == null) //if currently not holding anything
{
//perform raycast to check if player is looking at object within pickuprange
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, pickUpRange))
{
//make sure pickup tag is attached
if (hit.transform.gameObject.tag == "canPickUp")
{
//pass in object hit into the PickUpObject function
PickUpObject(hit.transform.gameObject);
}
}
}
else
{
if(canDrop == true)
{
StopClipping(); //prevents object from clipping through walls
DropObject();
}
}
}
if (heldObj != null) //if player is holding object
{
MoveObject(); //keep object position at holdPosition
RotateObject();
if (Input.GetKeyDown(KeyCode.Mouse0) && canDrop == true) //Mous0 (leftclick) is used to throw, change this if you want another button to be used)
{
StopClipping();
ThrowObject();
}
}
}
void PickUpObject(GameObject pickUpObj)
{
if (pickUpObj.GetComponent()) //make sure the object has a RigidBody
{
heldObj = pickUpObj; //assign heldObj to the object that was hit by the raycast (no longer == null)
heldObjRb = pickUpObj.GetComponent(); //assign Rigidbody
heldObjRb.isKinematic = true;
heldObjRb.transform.parent = holdPosition.transform; //parent object to holdpositionition
heldObj.layer = LayerNumber; //change the object layer to the holdLayer
//make sure object doesnt collide with player, it can cause weird bugs
Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), true);
}
}
void DropObject()
{
//re-enable collision with player
Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), false);
heldObj.layer = 0; //object assigned back to default layer
heldObjRb.isKinematic = false;
heldObj.transform.parent = null; //unparent object
heldObj = null; //undefine game object
}
void MoveObject()
{
//keep object position the same as the holdPositionition position
heldObj.transform.position = holdPosition.transform.position;
}
void RotateObject()
{
if (Input.GetKey(KeyCode.R))
{
canDrop = false;
playerMovement.enabled = false; // Desativa o script para bloquear o movimento e olhar
float XaxisRotation = Input.GetAxis("Mouse X") * rotationSensitivity;
float YaxisRotation = Input.GetAxis("Mouse Y") * rotationSensitivity;
heldObj.transform.Rotate(Vector3.down, XaxisRotation, Space.World);
heldObj.transform.Rotate(Vector3.right, YaxisRotation, Space.World);
}
else
{
playerMovement.enabled = true; // Reativa o script
canDrop = true;
}
}
void ThrowObject()
{
//same as drop function, but add force to object before undefining it
Physics.IgnoreCollision(heldObj.GetComponent(), player.GetComponent(), false);
heldObj.layer = 0;
heldObjRb.isKinematic = false;
heldObj.transform.parent = null;
heldObjRb.AddForce(transform.forward * throwForce);
heldObj = null;
}
void StopClipping() //function only called when dropping/throwing
{
var clipRange = Vector3.Distance(heldObj.transform.position, transform.position); //distance from holdPosition to the camera
//have to use RaycastAll as object blocks raycast in center screen
//RaycastAll returns array of all colliders hit within the cliprange
RaycastHit[] hits;
hits = Physics.RaycastAll(transform.position, transform.TransformDirection(Vector3.forward), clipRange);
//if the array length is greater than 1, meaning it has hit more than just the object we are carrying
if (hits.Length > 1)
{
//change object position to camera position
heldObj.transform.position = transform.position + new Vector3(0f, -0.5f, 0f); //offset slightly downward to stop object dropping above player
//if your player is small, change the -0.5f to a smaller number (in magnitude) ie: -0.1f
}
}
}
Thanks!!!! it is easy to implement and can be easily extended
Man, you are a King
Is there any way to include a text which tells what is the button to pick up the object. I have no idea where to put it since the pickup range is after the getkeydown. This would really help!
Hi! Yes that is definitely possible.
You should add a canvas gameobject to the workspace, and add a text object to it.
Then you can detect whenever a player mouses over the object you want to pick up by raycasting, checking if it hits the object.
If it does hit the object, get it's position and use it to set the position of the text, you will then have to convert the coords from worldspace to screenspace.
Then set the text of your canvas object to something like "Press E to pick up". If the raycast is not hitting any pick up objects then make sure the text is set to empty "".
So basically all you are doing is placing a UI object in your 3D space, moving it around from object to object and changing the text. Look up some guides on 3D UI elements if you are struggling, best of luck :)
@@jondevtutorials4787 Im sorry, but can you give me an example for the script since I'm still pretty new to coding.
This is for anyone who wants to rotate the object to world space!
Replace this:
heldObj.transform.Rotate(Vector3.down, XaxisRotation);
heldObj.transform.Rotate(Vector3.right, YaxisRotation);
With this:
heldObj.transform.Rotate(Vector3.down, XaxisRotation, Space.World);
heldObj.transform.Rotate(Vector3.right, YaxisRotation, Space.World);
Hope this helps! 🧀🧀
Absolute Legend, Thank you
Make sure that the "Static" checkbox is not ticked in the Inspector at the top right corner. Some objects have this ticked by default
hi! thank you so much for the tutorial! i'm a bit confused on how to lock the background lookaround rotation while you're rotating the item. could you advise on this? thanks!
lol been trying to do this for ages with some goofy ass spaghetti code when I realised I can yoink the code. :p
So, I didn't necessarily have an issue with adding the code to my player but when I go up to an object that has the "canPickUp" tag it does nothing.
same
what do i do?
When I click play, the object I want to pick up is just gone
Have you moved around, picking up an object with this code near a wall makes it clip into the wall, if you still don’t see it, it might be the layers
hI, can someone help me pls every time I try to click the "E" to pick up the object it doesn't do anything.
same
Man this is so gooood! Can u do a tutorial on an Inventory System?
why cant i pick up anythinggggg, i try to follow these tutoirals but nothing works
it didnt work for me either
@@interclone7968 same
add a rigid body to the object, probably a bit late but it worked for me
Did u try to add the tag?
Great video, but I do have one problem. Every time I try to pick up the sphere I want to pick up, nothing happens. I have it on the right tag, but on the default layer. When I try to put it on the Hold layer, it can be seen through walls. Any way these can be fixed?
Please help. It says the name "Pickable" does not exist in the current context. The name of my Layer is Pickable.
make sure to change the layername in the script as well
LayerNumber = LayerMask.NameToLayer("pickable");
should be in the start function
Hello, great tutorial. I will definitely use it in the future! One concern I do have is if your rendering the object above everything, doesn't that mean that you can see it through walls? Sorry if the answers obvious but I haven't used this system yet. Thanks
Hey thanks for the nice comment. The layer gets rendered above everything, and since we only assign the object to that layer when we are holding it, the object doesn't appear through walls when it is on the ground.
@@jondevtutorials4787 Thanks for letting me know :)
i can see the object through walls, how can i fix this?
It wont let me pick up the object
Same
which unity version did you used in this tutorial
Very good, thank you so much!!
Thank you! This worked great and was easy to implement.
Edit: Got it working how I wanted :)
I loved your tutorial and script it's so useful and great. But i've a question:
I want my pickable objects to be affected by my post process which is in my main camera object. How can i do that?
how does the script change when using third person and player input system?
Best tutorial
every time a pick up an item, another copy is on top of it. how do i get rid of that
Im a newbie of that. What is ur template you using? 3D, VR core, or something? Thanks
It worked but when i try on an imported 3d object it still clips through the wall for some reason
when I make the same settings in both of my cameras I think my unity only uses one camera and that is the pickupcamera in my unity everything goes black other than the objects in holdlayer. how can I fix it
amazing, dude
How can i change R to rotate the object to the Scroll wheel instead?
I don't have clear Flags and depth option in my camera inspector!
Are you using URP perhaps? If not that can you tell me what version of unity you are running?
@@jondevtutorials4787 yes I was using it and I turned it off and now I have them. But there is another issue with the code. When I pick up a cube for example and look around the cube changes its scale. Why is this happening?
@@jondevtutorials4787 I'm facing a weird issue sometimes when I throw an object, it doesn't always gets thrown forward. sometimes towards the player itself.
@@HiHoSHOW perhaps the player is blocking, try changing the point where it is being thrown from. Else check how direction is being calculated in the addforce method, perhaps you are using worldspace not local space.
@@jondevtutorials4787 i use urp, 2022.3. and i didnt have those two. and now my object is invisible when i picked it up.., any solution??
i guess im late but how can i remove the rotate feature
hello, i have some problem, the script works until i take the object in my hand, as soon as i press E and the game pauses
hey man i want to ask is it ok if i put your yt user in the credits for the game im working on? thanks
yeah no problem :) Appreciate it
idk why but all of the things i tested keeps resizing when i'm holding them and move my camera
my cube disappears when I press E. Can you please help
same broooo, how is it now??
Hi, i knwo this video is old but i'm trying to use your code. I have a weird problem. When i pick up an object his scale changes. Making more big or more little. Any idea whats happening?
same problem, did you fix it
I don't know if it's still relevant, but if the size of the Player model is different, this happens. So, if you set the player transform to 1,1,1, it will be fine. (It helped me)
Is there a way to make it have a certain rotation when you pick it up?
WHEN I PRESS E THE CUBE DISSAPEARS AND YES I PUT RIGIDBODY IN IT PLEASE HELP!!!
your pickupcamera isnt set to overlay
but i want tutorial how to do it i dont want to copy and paste script
Great tutorial! I've implemented the script and managed to get it working. But when I pick up and throw the object, the scaling of the object change. How can i fix this. And my camera also rotates when rotating the object, is there any way to fix that?
Same, any fix?
i dont want camera to move when rotating object
This is nice because the object doesn't move when it hits walls
Thank you so much
i got this error, pls help. (A game object can only be in one layer. The layer needs to be in the range [0...31])
Thanks so much!
This tutorial isnt working for me. It might be because I dont know how to reference my FPS script, but none of this actually works for me, man. Its always these seemingly easy tutorials that are the most complex. Or maybe im just stupid
Is it a way to make it to where only I can pick it up and nobody else able to touch it even when I drop it
Yes there is
I keep getting a layer error saying A game object can only be in one layer. The layer needs to be in the range [0...31] someone please help me rah
I was getting the same error. I fixed it by making sure my hold layer was labeled 'holdLayer' exactly like in the script. Alternatively you could change the script to match whatever you named your hold layer.
Hey, awesome video. I have a problem when picking up the item. I have a post process volume on my main camera, but when I pick up the item the effect doesn't apply onto the item until I drop it. I tried putting a volume on the other camera also, but it doesn't work still. Solutions??
Edit: Also, it clips through the map frequently.
Post process effects act on layers, you should have the option to select/add layers in the inspector for the post processing effect. As for the fact that it clips through the map, I think there is a StopClipping() func. that you may want to look at which tries to stop the the object from being placed through colliders. It's at the very bottom of the code, try editing the last few lines to your spec.
@@jondevtutorials4787 Thanks!
Unsure if you're still responding to comments or not but I have a slight problem. Picking up items is fine at first but for some reason after a bit it is a pain to pick up items. There's like a 90% chance the object cant be picked up and it gets very annoying. Any fixes? I'm using mesh colliders if that helps!
Remove the mesh collider
If anyone knows, why does the object teleport underneath my player when i drop it?
how can i do this in urp? there is no clearflags :(
same
hey man your script is work but i dont know how to throwing the object you have solution
How come when I throw it at the floor, it goes through the floor?
box collider
also what is ECM it have an error
Лучший
pls help me i use the urp not the normal one pls help :(
witch button is it to pick up
e
Hey has anyone figured this out in URP?
how do i drop it
The throw doesn’t work and now the cube is on my camera, forever
same :C
it doesnt work when i click e
assign rigidbody and box collider
@@ilhamnarendra770 it's still not working
thx
I'd have one suggestion. Use Interfaces instead of Tag, it's just better overall :P
it dont work for me
:/
Globox moment
can someone help me.., it doesnt work??
edit : i use urp and some things change with the camera. but i dont know why i cant pick up the object. i already assigned the tags and all the stuff, checked several times and i dont seem to find the problem why.
2nd edit = i figured it out, turns out it needed rigidbody. but now the object is invisible when its picked up. any solution??
me too!
Can you make a version of this to be mobile friendly?
Like for example.
Edit this script so then it can work for say making a mobile game
Not gonna like the video just since you said it in here but I will put it on the public playlist I credit my game jam entry to
I have a problem, when I take the object and move it to any side, it begins to deform slightly and lengthens or enlarges, how can I solve it?
hello how can ı use this when using urp ? do i just turn the broject into urp _?
does someone know why my cube streches after picking it up?