Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jrburger95 · Mar 13, 2014 at 07:23 AM · move an object

How can you make it that the FPS can pickup a object and move it around like in most source games

I am having trouble making a object so you can pickup a object say pressing E or clicking on it with the mouse. I have tried the DragRigidBody script and I have tried the Drag object Script and looked heaps of tutorials but nothing I do seems to work. Can anyone give me a step by step on how to do this.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Mar 14, 2014 at 12:49 PM 0
Share

Search unity gravity gun

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JuanseCoello · Mar 13, 2014 at 10:44 PM

I have read some tutorials of how to add a pickup to the characters hand, but for that you must have a character so that the pickup would be attached to the hand. You need to create a new script with this code.

using System; using System.Collections;

public class Pickup : MonoBehaviour { public Vector3 Offset = new Vector3(0f, 0f,0f); // Move the pickup slightly to match the hand public Vector3 ScalingFactorWhenHeld = new Vector3(0.4f, 0.4f, 0.4f); // Allows to scale the object smaller so that the player can hold it in its hand.

 private Vector3 InitialPosition; // Scales the pickup position when player dies.
 private Quaternion InitialRotation;
 private bool inRange = false;
 bool isHeld = false; // Tells if the object is being held.
 private Animation ItemAnim; // It is useful if the object has an animation

 private SphereCollider sphereCollider;

 void Awake() 
 {
     itemAnim = transform.Findchaild("PICKUPNAME").animation;
     sphereCollider = GetComponent("PICKUPNAME") as SphereCollider;
     initialPosition = transform.position; // Records initial position of the pickup
     initialRotation = transform.rotation;

 }

 void OntriggerEnter() // It is used when the pickup has volume
 {
     inRange = true;
 }

 void OntriggerExit()
 {
     inRange = false;
 }

 void LateUpdate() // You need another script called TP_Controller to make the statement isholding
 {
     if (inRange && !TP_Controller.Instance.isHolding && Input.GetKeyDown(KeyCode.E))
     {
         itemAnim.Stop;
         TP_Controller.Instance.IsHolding = true;
         TP_Controller.Instance.ObjectHeld = this;
         isHeld = true;
         TP_Contorller.Instance.Use();
     }

     if (isHeld) // if pickup is on the hand set the sphere collider to 0, TargetHand is the bone of the hand
     {
         sphereCollider.radius = 0;
         transform.localScale = ScalingFactorWhenHeld;
         transform.position = TP_Controller.Instance.TargetHand.position + Offset;
         transform.rotation = Quaternion.Euler(TP_Controller.Instance.TragetHand.rotation.eualerAngles.x,
             TP_Controller.Instance.TargetHand.rotation.eulerAngels.y + 90, 
             TP_Controller.Instance.TragetHand.rotation.eualerAngles.z)
     }
 }


 public void Reset()
 {
     isHeld = false;
         transform.position = initialPosition;
     transform.rotation = initialRotation;
     transform.localScale = new Vector3(1, 1, 1);
     sphereCollider.radius = 1; // Is used to reset the pickup to 1 agan, because when it is hels the collider is set to 0 to avoid collisions.
     itemAnim.Play();
 }

}

I found this script in a series of tutorials calles Unity 3rd person setup from 3d buzz it explains everything you need to know to create a character, and you can tweak it so you can play wih it and change it to a FPS, I highly recommend it, it was very useful to me and I dont speak english. But for the script I gave you you need to first create Another script called TP_Controller wich holds a character state called isHeld, that means that the character holds something in its hand. And therefore you go, you can ask me any question.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jrburger95 · Mar 14, 2014 at 07:43 AM 0
Share

Problems: 1. You just gave me a script you didn't tell me how to use it 2. The script keeps co$$anonymous$$g up with errors no matter what I do 3. I did make it clear I wanted a step by step on how to do this

Please if you can fix your mistakes or if you could give me the link to the video you found this at

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating an Object while Moving 0 Answers

Endless runner, road segments spawn speed 0 Answers

Physics2D and curved movement 1 Answer

How to drag object to snap? or move it only in 0.5f 1 Answer

Unity3D grenade not exploding correctly 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges