Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Pickup Backpack?

Discussion in 'Scripting' started by kneegrowdamus, Oct 3, 2014.

  1. kneegrowdamus

    kneegrowdamus

    Joined:
    Apr 22, 2014
    Posts:
    3
    hey everyone i would like to know how i could add a backpack to a unity project i have a character model with animations and stuff and how would i make it to where when your near or looking at the backpack you can press "E" or any button to pick it up and put it on your back
     
  2. aoe_labs

    aoe_labs

    Joined:
    Nov 4, 2013
    Posts:
    42
    In order to pick it up, you want to check for input.
    Code (CSharp):
    1. void Update() {
    2.     if (Input.GetKeyDown("e")) {
    3.         // do stuff here
    4.     }
    5. }
    The //do stuff here is where you would do the actual mounting of the backpack. I can think of two options:
    1. animation
    2. changing the transform of the backpack to be on the player's back.
    Can't help you with the first option. You might be able to create the anim yourself by editing an anim clip and moving the backpack while in record mode.

    In the second option, the mounting will look less realistic, but it will achieve the desired result. There are also two ways of doing this: either move the backpack instantaneously via scripting by changing its position to be the position of the player's back when the key is pressed; or lerp it there so that it takes time to move to the player's back.
     
  3. kneegrowdamus

    kneegrowdamus

    Joined:
    Apr 22, 2014
    Posts:
    3
    i don't know how to make it transform to the players back i don't know anything about scripting maybe a link to a scripting tutorial? imma go google some tuts up if anyone has the full code please post it for me thanks
     
  4. aoe_labs

    aoe_labs

    Joined:
    Nov 4, 2013
    Posts:
    42
    To move the object, you can do something like
    • transform.Translate(x,y,z) where x,y, and z are the amounts you want to translate by
    • Vector3.MoveTowards
    • Vector3.Lerp

    To get the position of where it needs to go, you can either
    • hard code the numbers (not recommended)
    • do something like transform.position = otherObject.transform.position; where otherObject is the object that it's moving to, like the player's back (recommended)
    Then you would need to make the backpack a child of the player (or the player's back) so that the backpack moves with the character. Something like backpack.transform.parent = otherObject.transform.

    You can PM me if you want more help. Since I don't have all the details, I can only help so much, but hopefully what I've mentioned here will be of assistance to you.
     
  5. kneegrowdamus

    kneegrowdamus

    Joined:
    Apr 22, 2014
    Posts:
    3
    yes one more thing where would i be able to find a backpack model ive tried sketchup and my trial has ran out and cant afford it
     
  6. aoe_labs

    aoe_labs

    Joined:
    Nov 4, 2013
    Posts:
    42
    Perhaps TF3DM or the Asset Store
     
  7. Jamcount

    Jamcount

    Joined:
    Apr 20, 2014
    Posts:
    44
    Blender is some nice and free 3D software. http://www.blender.org/