EASILY Pick up and Throw Objects | Unity 2018 Tutorial

Ойындар

In this updated tutorial, I go over the issues that the last video on this subject had, and we create a brand new system perfect for any game that involves picking up game objects! I also teach how to create a throw system that is easily modified, as well as implementing collisions and distance vectors.

Пікірлер: 312

  • @RyanRioga
    @RyanRioga5 жыл бұрын

    Great tutorial! I was super stumped on this and there was a few spots I completely forgot about or just didn't know. Super helpful and I was able to pick up my boxes in my project perfectly. Nice work!

  • @SamuelVirkola
    @SamuelVirkola4 жыл бұрын

    I've tried to search for stuff like this for so long. I am very surprised I didn't come across this tutorial. This video was perfect (for me at least). Thank you.

  • @kathrynprater2767
    @kathrynprater27673 жыл бұрын

    Thank you for this!! There are so many videos for this concept but they either only work for their code or do not show you the full code. Also, I have tried many with so many bugs. This is perfect and very adaptable.

  • @liam-iq3ji
    @liam-iq3ji5 жыл бұрын

    Your awesome thanks to much, the way you program is better to watch than anything I have ever found online thanks for helping so much. been hoping to make a game that can do this and I was having so many problems.

  • @ChrisBurns3D
    @ChrisBurns3D6 жыл бұрын

    Great tutorial mate, please keep making more

  • @umpteenthreason9627
    @umpteenthreason96275 жыл бұрын

    Great tutorial, with a few minor tweaks it even works fine in a 2D game.

  • @wanderwaffles3113

    @wanderwaffles3113

    5 жыл бұрын

    I mean the part of 3:24

  • @yalcngovyaprak8430
    @yalcngovyaprak84304 жыл бұрын

    Code; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Pickup : MonoBehaviour { float throwForce = 600; Vector3 objectPos; float distance; public bool canHold = true; public GameObject item; public GameObject tempParent; public bool isHolding = false; // Update is called once per frame void Update () { distance = Vector3.Distance (item.transform.position, tempParent.transform.position); if (distance >= 1f) { isHolding = false; } //Check if isholding if (isHolding == true) { item.GetComponent ().velocity = Vector3.zero; item.GetComponent ().angularVelocity = Vector3.zero; item.transform.SetParent (tempParent.transform); if (Input.GetMouseButtonDown (1)) { item.GetComponent ().AddForce (tempParent.transform.forward * throwForce); isHolding = false; } } else { objectPos = item.transform.position; item.transform.SetParent (null); item.GetComponent ().useGravity = true; item.transform.position = objectPos; } } void OnMouseDown() { if (distance

  • @beefbossfromwiisports

    @beefbossfromwiisports

    4 жыл бұрын

    thank you:) you probably just saved me like half an hour :)

  • @beefbossfromwiisports

    @beefbossfromwiisports

    4 жыл бұрын

    thank you:) you probably just saved me like half an hour :)

  • @hax2024

    @hax2024

    4 жыл бұрын

    hero

  • @DemonxModRx

    @DemonxModRx

    4 жыл бұрын

    what a legend

  • @shamoolmalik5472

    @shamoolmalik5472

    3 жыл бұрын

    Great Dude

  • @cyantifical
    @cyantifical6 жыл бұрын

    Thank you so much man! Helped out loads

  • @connorpayne2671
    @connorpayne26714 жыл бұрын

    This is exactly what I was looking for. I combined this with what I had already and added my own keys for things such as dropping and sticking the item in the air and it does exactly what I want. Thank you Now I just need to figure out how to make the object go back to its parent when it is moved around, like in Skyrim 😅

  • @mattwester9093

    @mattwester9093

    4 жыл бұрын

    Glad the tutorial helped you out!

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    Hey; You can try this: public GameObject originalParent; void Awake() { //Setting the original parent in the start of the scene originalParent = gameObject.transform.parent; } void OnMouseUp() { isHolding = false; //Setting the gameObject back under the original parent after letting go of it. gameObject.transform.parent = originalParent; }

  • @connorpayne2671

    @connorpayne2671

    4 жыл бұрын

    @@XnathOW I'll have to have a look to see if that does the job. Thank you

  • @mikethegamedev
    @mikethegamedev3 жыл бұрын

    thanks so much! i learned a new knowledge

  • @GrimBirthday
    @GrimBirthday4 жыл бұрын

    Wow really fun and easy thank you

  • @skitterlitter
    @skitterlitter3 жыл бұрын

    finally a tutorial that works THANK YOU

  • @mattwester9093

    @mattwester9093

    3 жыл бұрын

    Glad it helped!

  • @mattwester9093

    @mattwester9093

    3 жыл бұрын

    @Conshe Tumare are you getting any errors that I can help out with?

  • @fast07hzmc401

    @fast07hzmc401

    2 жыл бұрын

    @@mattwester9093 Hello im not getting any errors but for some reason i can't really pick up the cube, i can only drag it on the ground. Might you know what is wrong ?

  • @vini8v8

    @vini8v8

    2 жыл бұрын

    ​@@fast07hzmc401 Checks if the 'Guide' object is a child of your main camera. If it is the child of some other object (like your player, if your camera is not its child) the problem is there. The Guide must be a child of the camera. It works, but I need to find another way to do this, more efficient... :/

  • @mrsein
    @mrsein4 жыл бұрын

    Works GREAT! THX!!!

  • @mattwester9093

    @mattwester9093

    4 жыл бұрын

    Anytime, glad it helped!

  • @iuhchiuhhgbnr4213
    @iuhchiuhhgbnr42133 жыл бұрын

    Good tutorial thankyou

  • @darcygibbons2891
    @darcygibbons28914 жыл бұрын

    Thanks so much!

  • @fast07hzmc401
    @fast07hzmc4012 жыл бұрын

    Man you got to have a tutorial on the first person puzzle game you made (:

  • @toslytodie
    @toslytodie4 жыл бұрын

    when i pick up object with this script it's deforms!

  • @Zharkan16
    @Zharkan163 жыл бұрын

    I parent it to the cameras transform but it stops randomly in space when I walk around

  • @pepperj
    @pepperj6 жыл бұрын

    Hey great tutorial...Question I have: I can pick up and throw but after that I can't pick it up again when I walk over to it. Any Ideas? Thanks!

  • @AZ-qw1kz
    @AZ-qw1kz5 жыл бұрын

    If it isn't working for you, this is what fixed it for me. Make sure the "if (distance

  • @xxRobodragonxx
    @xxRobodragonxx4 жыл бұрын

    For some reason when i bump into the object that i am picking up it wont work at all. but when i get out of the distance area it will work, could this have to do with my game being a 3rd person not a first person game.

  • @farfadet46
    @farfadet466 жыл бұрын

    hi thanks you so mush for this good tutorial. but the "canhold" variable isn't used ? have you a second video in WIP ? ;)

  • @vanessanajem6491
    @vanessanajem64915 жыл бұрын

    How are you testing the game? I am moving using the arrows to step forward and backward and the mouse to turn directions, but i can't click on the object. Can you help please?

  • @kingbrodan
    @kingbrodan5 жыл бұрын

    what if you have multiple players in the scene, like a multiplayer game how do you account for the different cameras?

  • @BlanketsWilson
    @BlanketsWilson6 жыл бұрын

    Hey what's up, this is great! Is there any way to change it where to pick up the object with the lmb and also throw it with the lmb? Also, I've been trying to change the distance so the player can pick up the object when closer to it but I feel like it's getting further away. Talk soon,

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Brian Wilson for the distance could it be that your bool isHolding = false; Void OnMouseOver If(input.getmousebuttondown(0)) If(isHolding == false) IsHolding = true Else if(isHolding == true) //put throw code here Hope you get the general idea of how that would work. Sorry it's not exact code but in writing this from my phone. Happy coding, Matt

  • @Andrewcompton22
    @Andrewcompton224 жыл бұрын

    Do you have a video or can you make a video on how to do this with a 2D game? or do I just need to change it to Vector2's? or can I just use this to achieve the same on 2D? lol sorry for all the questions

  • @gilgusinsky2513
    @gilgusinsky25134 жыл бұрын

    is there a way to do this with 2d, i mean be able to "pick up" a sprite and throw it around with ur mouse? i have a script for the pick up where mouse down moves the sprite, but i dont know how to send it flying in the direction i "throw it."

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    Depends on "how" you're trying to throw it? Swinging your mouse? Or is it held by a character that throws it at the direction of the cursor? For the latter you need to find the directional vector that is formed between the player and cursor, and use that Vector in the AddForce function (instead of the tempParent.transform.forward) that is being used in this tutorial.

  • @michaelberger4942
    @michaelberger49425 жыл бұрын

    Hi thanks for this tut..., works, but when i start Gamemode the rigidbody is picked up and cant be dropped... what's wrong?

  • @johnsummers101
    @johnsummers101 Жыл бұрын

    Thank you for this! So, would you really want the throw and pickup to be in the same class? Or would they be separate classes?

  • @prathmeshthakkar4563
    @prathmeshthakkar45635 жыл бұрын

    Hey matt, Great tutorial! But I am having a problem in which it can detect the mouse presses (and checks isholding) but the object deosn't move. Any ideas?

  • @BT-cp4lq

    @BT-cp4lq

    5 жыл бұрын

    same is happening to me I have no idea why

  • @larrynachos
    @larrynachos4 жыл бұрын

    Thank you so much for this tutorial! One problem though... with some bigger objects, I can lift the object and rotate myself with it, but as soon as I use WASD to move around, the object and pickup guide remain where they are, only moving in relation to rotation. I can pick up and carry a ball with me just fine, but larger crates won't move. Any ideas? Thanks again!

  • @jackjames5519

    @jackjames5519

    4 жыл бұрын

    following this for answers

  • @smifyy

    @smifyy

    3 жыл бұрын

    bit late but I added this and it worked for me: item.GetComponent().constraints = RigidbodyConstraints.FreezePosition; when you pick up the object and item.GetComponent().constraints = RigidbodyConstraints.None; when you let go or throw it

  • @bomdiabatata

    @bomdiabatata

    2 жыл бұрын

    @@smifyy added where?

  • @nguyenvanat2149
    @nguyenvanat21493 жыл бұрын

    thank a lot :>

  • @Assniffer
    @Assniffer5 жыл бұрын

    Will this works on enemy's as well like if i want to grab them then chokeslam them like in wrestling game's?

  • @aayushshrestha2871
    @aayushshrestha28714 жыл бұрын

    It was very helpful. But I just got a problem that whenever I pick up the object and try to move around the object remains in the same position. Surprisingly, it works on the standard FPS controller of the unity but not in the custom fps controller I made. All the things work perfectly except the move around with the object part. Just found out that it only works on the fps controller with character controller, not on the fps controller with rigid body. Is there any way to solve this problem?

  • @kcatthirtysix

    @kcatthirtysix

    3 жыл бұрын

    I’m hoping he responds, I’m having the same issue

  • @baxterclagmoar9333
    @baxterclagmoar93335 жыл бұрын

    Can pick up objects but they stretch and deform whilst held??? No idea why. Works in a brand new fresh scene, but not in the scene I need it in.

  • @BradyHege
    @BradyHege4 жыл бұрын

    Hey, I'm curious what I can do (if anything) to prevent my object from warping after being picked up. I'm testing this code on a simple sphere and it turns into basically an egg. What am I doing wrong? Thanks in advance to anyone who can help!

  • @awesomepotato292

    @awesomepotato292

    4 жыл бұрын

    I have the same problem. As far as I know, the problem is because one of the parents of the guide has some scaling and it causes that. I'm still looking for a fix that allows me to scale my player.

  • @piertFB
    @piertFB5 жыл бұрын

    are you using a vr tool? or just using the computer to do that movements?

  • @Moonriderr
    @Moonriderr4 жыл бұрын

    Yo, i was searching something in stackoverflow and i saw u tutorial there.I saw some guy telling u its not good to update some value in the loop, but i cannot simply find the topic anymore.Can u post the optimized script here? Thanks u! :)

  • @contagentdev6173
    @contagentdev61736 жыл бұрын

    thamks man

  • @contagentdev6173

    @contagentdev6173

    6 жыл бұрын

    i ment thanks]

  • @genuinefraud8262
    @genuinefraud82625 жыл бұрын

    UnassignedReferenceException: The variable item of PickUp has not been assigned. You probably need to assign the item variable of the PickUp script in the inspector. PickUp.Update () (at Assets/PickUp.cs:37) EDIT: oh nvm

  • @ZombiehuntersComeback
    @ZombiehuntersComeback4 жыл бұрын

    Hi great tutorial on how to pickup and throw items I was looking for this for a while now. I have one problem though. When I pickup an item the item goes through another object instead of colliding with it. I've checked and detectCollisions is set to true. I've pasted the code under here so you could tell me what I did wrong. float throwForce = 600; Vector3 objectPos; float distance; public bool canHold = true; public GameObject item; public GameObject tempParent; public bool isHolding = false; // Update is called once per frame void Update() { distance = Vector3.Distance(item.transform.position, tempParent.transform.position); if(distance >= 1f) { isHolding = false; } //Check if isholding is true if (isHolding) { //Picks up item and holds it in front of you item.GetComponent().velocity = Vector3.zero; item.GetComponent().angularVelocity = Vector3.zero; item.transform.SetParent(tempParent.transform); item.transform.position = tempParent.transform.position; item.transform.rotation = tempParent.transform.rotation; //Checks if the right mouse button has been pressed if (Input.GetMouseButtonDown(1)) { item.GetComponent().AddForce(tempParent.transform.forward * throwForce); isHolding = false; } } else { //leaves the picked up item at it's last position if isHolding is false objectPos = item.transform.position; item.transform.SetParent(null); item.GetComponent().useGravity = true; item.transform.position = objectPos; } } void OnMouseDown() { if(distance

  • @natalieweishuhn3283

    @natalieweishuhn3283

    4 жыл бұрын

    You didn't add a rigidbody to the box in the editor.

  • @MayurBhagat10
    @MayurBhagat105 жыл бұрын

    Thanks for nice tutorial. You can update tutorial with just two things. 1)If pickable item is in range then show UI prompt like some sign that item is ready to be picked up.I guess enabling 2d ui image part of canvas makes sense. 2) Item should not be dropped automatically with coliding issue. We should resist it in some way. You can decide how to handle it. Thank You !

  • @Alex-vu5uu
    @Alex-vu5uu6 жыл бұрын

    hi, can you explain the function to use the key E instead of on mouse down? thanks a lot!

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Alex x instead of the function OnMousdDown, use OnMouseOver and then add an additional line of code right under that saying if(Input.GetKeuDown(KeyCode.E)) Then put the rest of the code down here. Hope that helps

  • @lairlair2
    @lairlair23 жыл бұрын

    Super helpful thank you!! Two ideas to improve the code (maybe?): - declaring a rigidbody at the beginning and define it in the awake function to avoid typing "item.GetComponent ()." a couple of times. private Rigidbody rb; private void Awake() { rb = item.GetComponent(); } - Use colliders set as triggers instead of distance. It allows you to pick up objects of different sizes and shapes. The downside is you'll need to set up a trigger for every single object. I'll have to test that one

  • @jamesqueen2673
    @jamesqueen26734 жыл бұрын

    Hello, Is there any way to pick up the item without it rotating? i notice when i pick up the item it rotates based off of where i'm looking with the mouse. I want my object to stay flat when i pick it up not rotate on the y axis

  • @otamatonegaming

    @otamatonegaming

    2 жыл бұрын

    freeze the rigidbody constraints

  • @ThatGuyDownInThe
    @ThatGuyDownInThe4 жыл бұрын

    If I already have something else mapped to the mousebutton what should I do?

  • @lazerfate385

    @lazerfate385

    4 жыл бұрын

    e key

  • @kingdom216
    @kingdom2163 жыл бұрын

    How does the script change when one is using a third person controller?

  • @rbanister100
    @rbanister1002 жыл бұрын

    When making video's, you need to make sure the INS (the INSERT KEY), is NOT pressed, to get rid of the BLOCK CURSOR. in Visual Studio.

  • @stevengibson4773
    @stevengibson47734 жыл бұрын

    Please add your scripts in the description. Helpful for us looking at this tutorial in later years to ensure we aren't wasting our time if it doesn't compile

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    This code is so basic that there shouldnt be any issues tbh.

  • @stevengibson4773

    @stevengibson4773

    4 жыл бұрын

    ​@@XnathOW The point of snippet is so people can check that the code still works without copying line by line. A big waste of time. As time goes on APIs change, and even now my comment is 7 months old which means even more likely that this code will not work as is.

  • @Ariel-uo7le
    @Ariel-uo7le5 ай бұрын

    thank you so muchhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @flymilk1
    @flymilk14 жыл бұрын

    it's not working it says I have errors like expected. insert a semicolon at the end I looked and it has a semicolon.

  • @youknov4748
    @youknov47486 жыл бұрын

    Hello, I did everything like in the video but when I try to throw the object it doesn't throw forward, it throws sidewards (to the right side). No matter how I rotate myself it throws to the right side. What can I do?

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Melon Intros you could try changing the direction of the thrust / throw. I think something like Vector3.left instead of Vector3.forward should work fine.

  • @youknov4748

    @youknov4748

    6 жыл бұрын

    Matt Wester Hmm I gotta look but I can't remember a Vector.right or something, maybe I have to rotate my empty?

  • @youknov4748

    @youknov4748

    6 жыл бұрын

    je I am stupid the z axis pointed to the right side xD so I fixed it and it works! Thanks!

  • @ancolia8772
    @ancolia87723 жыл бұрын

    yeah but i want the player to be able to hold multiplayer objects. how you do that?

  • @theleeboys1098
    @theleeboys10984 жыл бұрын

    When I load the scene in game mode the object with this script just disappears, anyone know how to fix that?

  • @thg1nrediar
    @thg1nrediar2 жыл бұрын

    Good

  • @gray525
    @gray5253 жыл бұрын

    When i try and add it it gives my the classname and file name do not match

  • @temp7720
    @temp77204 жыл бұрын

    Thank you for code. I got it working but I have one small problem. When I look up my box goes up to far and then gets flattened. It does not stay nicely in view like your demo. Any thought? Thank you agen.

  • @northdiddles

    @northdiddles

    4 жыл бұрын

    Im working on a fix ill let you know later.

  • @ethanjarveyocampo1199
    @ethanjarveyocampo11994 жыл бұрын

    This looks great but I have problem that I can't pick it up :(. It just moves along the ground..... Is the first person controller strictly necessary?

  • @Nuff.x

    @Nuff.x

    4 жыл бұрын

    well kind of, the problem you may have is that the guide is not a child object of the camera as id assume you have it set as the guide as the childed object of the actual character. so honestly you could try making the guide a child object of your third person camera but I don't think you would get the results you are looking for

  • @ethanjarveyocampo1199

    @ethanjarveyocampo1199

    4 жыл бұрын

    @@Nuff.x Yeah I figured that out kinda late, but I finally got it! :) thanks for the tip man

  • @Nuff.x

    @Nuff.x

    4 жыл бұрын

    @@ethanjarveyocampo1199 np man

  • @EmuTheEmo
    @EmuTheEmo5 жыл бұрын

    Everything works. But just 1 issue. When I walk around the object stays in the same place. I can move it by looking around but if I try to move it won't move with me. No errors in the code and it's the same as yours. I've typed the code out a few times and still has the same issue

  • @FuffoloWorks

    @FuffoloWorks

    5 жыл бұрын

    Same! Mine appears also to be working only on the x axis if i look around

  • @brillerment

    @brillerment

    5 жыл бұрын

    @@FuffoloWorks Make sure your guide GameObject is a child of FirstPersonCharacter, and not FPSController. That should fix that.

  • @forte9300

    @forte9300

    5 жыл бұрын

    Brent Miller Thanks so much that worked! The object doesn’t throw though..

  • @MyNeighborThomasPlus
    @MyNeighborThomasPlus6 жыл бұрын

    Hi Glad to see you Matt ! And Thanks for Upload this Pick Up Script. um.. I just have a Simple Question for You. I Written Your Code and Apply to Item. and I can see How to Pick Up the Item But If i Throw this Item it doesn't Throw to forward just Thrown back. I dont Know Why Am i Wrong With this Code Thank you For Read This. Have a good Day Matt. ^_^

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    shiwook cho it sounds like you may have a different rotation than me on your character. Something simple you can do is replace one word in the code. In the section of the script where we handle throwing, instead of saying vector3.forward, put in vector3.back, and that should fix your problem! Happy coding.

  • @MyNeighborThomasPlus

    @MyNeighborThomasPlus

    6 жыл бұрын

    Oh My God... You Are Genius .. I dint think about that Vector3.back Wow It Works For me Thank You Matt. ~(^~^~

  • @paulschmidt1689
    @paulschmidt16896 жыл бұрын

    Everytime I playtest isHolding always starts with the box checked for true and I can't uncheck it any help? using System.Collections; using System.Collections.Generic; using UnityEngine; public class PickUp : MonoBehaviour { float throwForce = 600; Vector3 objectPos; float distance; public bool canHold = true; public GameObject item; public GameObject tempParent; public bool isHolding = false; // Update is called once per frame void Update () { //Check if isHolding if (isHolding = true) { item.GetComponent ().velocity = Vector3.zero; item.GetComponent ().angularVelocity = Vector3.zero; item.transform.SetParent (tempParent.transform); } if (Input.GetMouseButtonDown(1)) { } } else { objectPos = item.transform.position; item.transform.SetParent (null); item.GetComponent().useGravity = true; } } void OnMouseDown () { isHolding = true; item.GetComponent().useGravity = false; item.GetComponent().detectCollisions = true; } void OnMouseUp(){ isHolding = false; }

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    In your if it needs to be if (isHolding == true), 2x == to check

  • @aaronwilk250
    @aaronwilk2503 жыл бұрын

    can you help me, When I pick up objects and move them around they will deform.

  • @Cronoss95
    @Cronoss956 жыл бұрын

    Heyho! Your script looks great, anyway I am not able to pick anything up! I wrote the script 3 times now, and I am still not able to move anything. Wich button do I have to press? :(

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    R Musterman this script uses the left mouse button to pick up, but you have to hold it down. To throw the object you have to press the right mouse button.

  • @Cronoss95

    @Cronoss95

    6 жыл бұрын

    Ahh, i found the problem! I changed the values of the distance from 1f to 50 and now everything works (well, I cant lift anything above my head, but at least this works now :D) - do you know why this is happening? Thank you for your reply!

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    R Musterman I had a similar issue when I was updating the turorial, for me it was as simple as making sure my guide object was a child to the camera object of your player, if you are using standard assets I think it is called FPSCharacter or something like that

  • @fast07hzmc401
    @fast07hzmc4012 жыл бұрын

    Like uh i don't really know what i did wrong. I can only drag the object on the ground and not really pick it up in the air and move it. Does someone know what's wrong ?

  • @accesmadagascar
    @accesmadagascar4 жыл бұрын

    im getting error CS0101 how do you fix it?

  • @hackerhd9203
    @hackerhd92035 жыл бұрын

    every time i move the object the scale is changing can someone help me

  • @rafioz0

    @rafioz0

    4 жыл бұрын

    I also have this problem :

  • @Maggiethegsd

    @Maggiethegsd

    4 жыл бұрын

    @@rafioz0 press w and then move it...

  • @kerodical9237
    @kerodical92375 жыл бұрын

    Well, how if I were to use this on multiple objects? I mean how about performance?

  • @lucianopereira3612

    @lucianopereira3612

    5 жыл бұрын

    It will be pretty bad since he's checking the distance every frame regardless if anything is being held or if anything has a mouse over it. You should update his code to only update the distance variable only if isHolding is true and also down at the OnMouseDown function. You should also not do getComponent() so many times- do it once and save it to a variable (preferrably do this in a Start() method in the script).

  • @kasinduudara4040
    @kasinduudara40406 жыл бұрын

    I got a Unassigned Refarance Exception this line objetpos = items.transform.position; what should have to do

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    kasindu udara I think you just need to remove the s in items, as in the script it is defined as item. Hope that helps!

  • @kasinduudara4040

    @kasinduudara4040

    6 жыл бұрын

    not working , it is not compilation error it is run time error

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    kasindu udara then it sounds like you may have forgotten to assign your variables?

  • @brettpitmanii9102
    @brettpitmanii91025 жыл бұрын

    what about 3rd person controller?

  • @samgd5260
    @samgd52602 жыл бұрын

    why does it not follow well on the x axis and not at all while moving

  • @ShootLuckGaming
    @ShootLuckGaming5 жыл бұрын

    When I pick up my object i can move it around, it will only spin with me, when i move forward or backward it will remain in place, help please

  • @yunussutanti2788

    @yunussutanti2788

    4 жыл бұрын

    item.transform.position = tempParent.transform,position; item.transform.rotation = tempParent.transform.rotation; it's should works fine, but it may look more unrealistic

  • @yunussutanti2788

    @yunussutanti2788

    4 жыл бұрын

    +Shoot Luck Gaming

  • @TheDynamicDudes

    @TheDynamicDudes

    4 жыл бұрын

    @@yunussutanti2788 where in the code do you put this?

  • @TheDynamicDudes

    @TheDynamicDudes

    4 жыл бұрын

    @@yunussutanti2788 nvm i just put the guide as a child of my camera rather than my character controller and it works fine

  • @Nuff.x

    @Nuff.x

    4 жыл бұрын

    @@TheDynamicDudes bruh i had a similar ish problem and making the camera the guides parent solved it fro me thank you!!

  • @joshuatran3070
    @joshuatran30705 жыл бұрын

    When I try to pick it up, it disappears. Any fixes on this?

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    Id guess the child object you placed under the camera is somewhere else other than on the player? Or it has a rigidbody and isnt kinematic

  • @toastedcracker1499
    @toastedcracker14994 жыл бұрын

    I have a question what is the guide?

  • @bobby-goody
    @bobby-goody5 жыл бұрын

    every time i pick up my object and look around it moves and the scale changes the object deforms itself and wont stay in the middle of the screen like yours can u help me please?

  • @baxterclagmoar9333

    @baxterclagmoar9333

    5 жыл бұрын

    Same problem here... It worked fine when I created a brand new scene, but doesn't work in the scene I need it to... Really frustrating.

  • @bobby-goody

    @bobby-goody

    5 жыл бұрын

    JuBable okay cheers mate

  • @alexanderthegreat7462
    @alexanderthegreat74623 жыл бұрын

    how to adjust how close the player can interact with the object?

  • @mattwester9093

    @mattwester9093

    3 жыл бұрын

    Change the distance float in the script

  • @CodiciPythonici
    @CodiciPythonici4 жыл бұрын

    doesn't work

  • @maksous
    @maksous6 жыл бұрын

    Great tutorial, but in my case something is wrong. I have a character, camera attached to it and then guide attached to camera. Basically, I can't pick up item - by left clicking, but when I left click on it, the scale of item seems to be changing, and when I right click while holding left button - it actually throws the item and holds it (I can't drop it tho). Got any idea how to fix this? :D

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    maksous1 be sure that in the OnMouseDown function that you are changing the transorm.position, as I have heard that only changing the .transform will edit the scale. Hope that helped!

  • @maksous

    @maksous

    6 жыл бұрын

    In OnMouseDown method I have: if(distance = 1f) { isHolding = false; } if (isHolding == true) { item.GetComponent().velocity = Vector3.zero; item.GetComponent().angularVelocity = Vector3.zero; item.transform.SetParent(tempParent.transform); if (Input.GetMouseButtonDown(1)) { item.GetComponent().AddForce(tempParent.transform.forward * throwForce); isHolding = false; } else { objectPos = item.transform.position; item.transform.SetParent(null); item.GetComponent().useGravity = true; item.transform.position = objectPos; } } } Basically, I really have no clue what is wrong :P

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Could you list any errors you are getting? At first glance your script seems fine

  • @maksous

    @maksous

    6 жыл бұрын

    Matt Wester yeah, thats the thing - no errors whatsoever. Just not working :|

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Did you remember to assign all the variables in the inspector?

  • @Laatikkoz
    @Laatikkoz2 жыл бұрын

    pls tell me what is wrong in script

  • @lousev3485
    @lousev34854 жыл бұрын

    i cant raise or lower the cube any idea how to fix that

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    You need to parent the object to player camera or object under the camera

  • @ONIVSTA
    @ONIVSTA2 жыл бұрын

    WHAT DO YOU RPESS TO PICK IT UP

  • @mattwester9093

    @mattwester9093

    2 жыл бұрын

    If you followed the video then press and hold the left mouse button to pick it up.

  • @JOHNSMITH-sj3lg
    @JOHNSMITH-sj3lg3 жыл бұрын

    the script dosent work for me i have no errors and make all the stuff u make can u help pls?

  • @hendryvarianto
    @hendryvarianto5 жыл бұрын

    Everytime i grabbed the object, it'll fall slowly .. help ?

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    Forgot to disable RigidBody.Gravity

  • @FweddyFwazbear
    @FweddyFwazbear5 жыл бұрын

    Awesome video, but can you give us the code? I have tried to put it out myself, but I have had issues. can you paste it into the description or reply it to me?

  • @fast07hzmc401

    @fast07hzmc401

    2 жыл бұрын

    so what happen did you fix it ?

  • @FweddyFwazbear

    @FweddyFwazbear

    2 жыл бұрын

    @@fast07hzmc401 I never figured it out

  • @cyx7784
    @cyx77843 жыл бұрын

    The cube doesn't look up with me. Any ideas?

  • @stancollins1510
    @stancollins15104 жыл бұрын

    can u add script to description?

  • @mr_kwkd
    @mr_kwkd4 жыл бұрын

    uhm does anyone know why when i pick it up the object stretches itself? I know this is 8 months old but if anyone sees this can you help?

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    It is because you put it as a child of your player, and your player is stretched (Scale), it copies the same amount of scale. The object holding the item needs to be at 1.0 scale in all Axis

  • @crimson3393
    @crimson33933 жыл бұрын

    The object doesnt move with me when i walk around, any ideas?

  • @rodovicky7534

    @rodovicky7534

    3 жыл бұрын

    yeah same thing is happening with me tooo

  • @starstorms21
    @starstorms216 жыл бұрын

    hey dude my cube isnt moving in the y axis at all, any ideas?

  • @starstorms21

    @starstorms21

    6 жыл бұрын

    nevermind i didnt parent it to the camera Xp

  • @mattwester9093

    @mattwester9093

    6 жыл бұрын

    Yea i had that problem too setting it up, glad you figured it out

  • @starstorms21

    @starstorms21

    6 жыл бұрын

    btw do you know a way i can make the object move closer to the player using the scroll wheel? or maybe rotating it using Q & E

  • @starstorms21

    @starstorms21

    6 жыл бұрын

    thank god i found this tutorial, it works like a charm after the parenting issue being fixed

  • @drigozx
    @drigozx4 жыл бұрын

    Every Time I Move the Object The Scale Keeps Increasing, Any Fixes?

  • @Maxspeedtofast
    @Maxspeedtofast5 жыл бұрын

    wished you had made screen shots of the scripting or just added to the description

  • @GrimBirthday

    @GrimBirthday

    4 жыл бұрын

    You learn more by doing

  • @JonahDominguez

    @JonahDominguez

    4 жыл бұрын

    just pause the video

  • @5ManaAndADream
    @5ManaAndADream4 жыл бұрын

    this is cool, but you cannot jump, the ball will not follow you vertically.

  • @zacharybird5400
    @zacharybird54005 жыл бұрын

    ok i get it picked up but it is not thowing

  • @beefbossfromwiisports
    @beefbossfromwiisports4 жыл бұрын

    how do you make it work when you press a certain key?

  • @mattwester9093

    @mattwester9093

    4 жыл бұрын

    As I mentioned in the video, you would want to use the function OnMouseOver instead of OnMouseDown. Then inside the function you would check for the input key you want.

  • @beefbossfromwiisports

    @beefbossfromwiisports

    4 жыл бұрын

    Matt Wester okay, I didn’t understand what you meant at first but now that I see it in text I understand, I guess my brain just works like that:) thanks for your help!

  • @mattwester9093

    @mattwester9093

    4 жыл бұрын

    @@beefbossfromwiisports glad I could help. Any other questions just let me know!

  • @beefbossfromwiisports

    @beefbossfromwiisports

    4 жыл бұрын

    @@mattwester9093 Here's my script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class FancyPickUP : MonoBehaviour { float throwForce = 600; Vector3 objectPos; float distance; public bool canHold = true; public GameObject item; public GameObject tempParent; public bool isHolding = false; // Update is called once per frame void Update () { distance = Vector3.Distance (item.transform.position, tempParent.transform.position); if (distance >= 1f) { isHolding = false; } //Check if isholding if (isHolding == true) { item.GetComponent ().velocity = Vector3.zero; item.GetComponent ().angularVelocity = Vector3.zero; item.transform.SetParent (tempParent.transform); if (Input.GetMouseButtonUp (1)) { item.GetComponent ().AddForce (tempParent.transform.forward * throwForce); isHolding = false; } } else { objectPos = item.transform.position; item.transform.SetParent (null); item.GetComponent ().useGravity = true; item.transform.position = objectPos; } } void OnMouseUp() { if (distance

  • @Powerpuffsama
    @Powerpuffsama4 жыл бұрын

    Followed the tutorial exactly and it doesn't even work. Can't even pick up objects.

  • @kennethbhasme9094
    @kennethbhasme90943 жыл бұрын

    Can someone please share link as to where I can get fps controller asset

  • @kingdom216

    @kingdom216

    3 жыл бұрын

    unity assets/ standard assets

  • @grzesiufranek9296
    @grzesiufranek92965 жыл бұрын

    i have error: error CS1513: } expected

  • @cgs7663

    @cgs7663

    5 жыл бұрын

    just put a } on that line

  • @gamesfox8768
    @gamesfox87684 жыл бұрын

    I have a problem, my item won't move up or down.

  • @gamesfox8768

    @gamesfox8768

    4 жыл бұрын

    nvm, parented to camera and worked. thanks for the awesome tutorial!

  • @Walllam

    @Walllam

    4 жыл бұрын

    @@gamesfox8768 couldnt figure out why it didnt work for me, thanks for telling me how you fixed it

  • @salemisjuucy
    @salemisjuucy4 жыл бұрын

    when i move the camera the object doesnt move with it, it stays on the floor, can someone please help asap

  • @northdiddles

    @northdiddles

    4 жыл бұрын

    You need to put the guide on the camera so it rotates with the camera.

  • @salemisjuucy

    @salemisjuucy

    4 жыл бұрын

    Wilkie Noob but when I do that when I look up the cube distorts and and changes shape, i haven’t been able to find a fix for that just yet.

  • @northdiddles

    @northdiddles

    4 жыл бұрын

    @@salemisjuucy Im working on a fix. I think its the rotation and scale of the object. Idk yet

  • @northdiddles

    @northdiddles

    4 жыл бұрын

    @@salemisjuucy Haven't found ought

  • @northdiddles

    @northdiddles

    4 жыл бұрын

    @@salemisjuucy Ill work on it later

  • @hendryvarianto
    @hendryvarianto5 жыл бұрын

    helppp everytime i clicked on the cubed, it changes size...

  • @rafioz0

    @rafioz0

    4 жыл бұрын

    @@uremi. I also have this problem :

  • @rafioz0

    @rafioz0

    4 жыл бұрын

    @@uremi. using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThrowObject : MonoBehaviour { public Transform player; public Transform playerCam; public float throwForce = 10; bool hasPlayer = false; bool beingCarried = false; public int dmg; private bool touched = false; void Update() { float dist = Vector3.Distance(gameObject.transform.position, player.position); if (dist

  • @vini8v8

    @vini8v8

    4 жыл бұрын

    I had the same problem, in my case the problem was: my camera has its Scaling changed (1, 0.7, 1) I fixed it to (1, 1, 1) and it worked.

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    @@uremi. Not about the code; Scaling of the parent will be transferred to the lifted object.

  • @XnathOW

    @XnathOW

    4 жыл бұрын

    @@rafioz0 Not about the code; Scaling of the parent will be transferred to the lifted object.

  • @mumiaminteh6786
    @mumiaminteh67864 жыл бұрын

    Can i get the first person controller code?

  • @mattwester9093

    @mattwester9093

    4 жыл бұрын

    Hey, sorry, but the video is pretty outdated now, and I have not done much programming in the last couple of years. I don't have access to the fps controller script, as I believe Standard Assets is no longer supported.. I know this video is pretty outdated as well, so I will see about updating it with a new FPS controller

Келесі