Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 misterxxx · Sep 15, 2011 at 06:29 PM · throwpick upthrowing

How To Throw anything ?

Hey everybody, This sound very Silly but i'm working on a new game and i cant Programming or Modelling I need to throw a object called "Hard drive" I just want to pick it up and Throw it can someone give me a script please im already looking for a script for already 5 days or more.

Comment
Add comment · Show 5
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 Scribe · Sep 15, 2011 at 06:42 PM 0
Share

yes it is very silly. In 5 days you could have learnt to script it yourself, your unlikely to get anyone to just write you a script and honestly you really haven't got a chance at making a game if you cant model or write script

avatar image syclamoth · Sep 16, 2011 at 04:13 AM 0
Share

if you're working on a game and you can't program or model... what are you doing?

avatar image misterxxx · Sep 16, 2011 at 11:23 AM 0
Share

i can talk,speak,write in english Very Good ,my vocabulary isnt just the best

avatar image Scribe · Sep 16, 2011 at 02:50 PM 0
Share

wow I admit i was wrong, someone actually did write you a script! also its not your english thats so much of a problem its the fact that you need to learn some scripting language, I would suggest unityscript first as there are a lot of resources and its quite easy to pickup in a short amount of time. I'm not the best modeler for sure but I have learn't enough on blender to make basic things or alter resources I find :) good luck

avatar image asafsitner · Sep 16, 2011 at 03:22 PM 1
Share

Hey, it's a good practice for me as well, and if someone is a little happier with it around, why not? :)

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by asafsitner · Sep 15, 2011 at 07:20 PM

You might want to make an inventory for the player, then upon pickup (collision probably) add the prefab to the inventory and destroy it. Then upon throwing it (probably a key press) you'll instantiate the prefab and remove it from the inventory. But really, making games isn't as easy as drag-n'-drop, even with tools such as GameMaker or FPSCreator. If you want to make games you need to know game-making-related things, such as scripting (and really there's no reason you can't learn JavaScript at the very least).

Example script (c#):

 using UnityEngine;
 using System.Collections;
 
 public class ThrowTest : MonoBehaviour
 {
     public Transform Inventory;
     public float ThrowDistance = 2f;
 
     void OnCollisionEnter (Collision collision)
     {
         if ( collision.transform.tag == "pickup" )
         {
             Inventory = collision.transform;
             Destroy(collision.transform.gameObject);
         }
     }
 
     void Update()
     {
         if (Input.GetKeyDown("space"))
         {
             var thrownItem = Instantiate(Inventory, transform.position, Quaternion.identity) as Transform;
             thrownItem.name = Inventory.name;
             thrownItem.Translate(0, 0, ThrowDistance);
             Inventory = null;
         }
     }
 }
Comment
Add comment · Show 3 · 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 misterxxx · Sep 16, 2011 at 11:25 AM 0
Share

no ,i dont want to get an inventory just to pick up something and to throw it,i already learning javascript but i think this can take a while can you make a second code for me please ?

avatar image asafsitner · Sep 16, 2011 at 12:01 PM 0
Share

The inventory is just a temporary container for whatever you pick up. But I think you mean something else, like the player carrying the object while it's still visible on screen? (possibly half-transparent like in deus-ex)

avatar image misterxxx · Sep 16, 2011 at 12:05 PM 0
Share

yes still visible

avatar image
1

Answer by misterxxx · Sep 16, 2011 at 11:30 AM

I know its stupid but i can modelling just not so good and i will learn javascript now i just need to find something in german

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 CHPedersen · Sep 16, 2011 at 11:18 AM 1
Share

No, you need to learn english, while you're at it. That way, you'll be able to benefit from A LOT more of the examples you find online, AND you won't have to listen to german voices dubbed on top of hollywood movies. :-D

avatar image
1

Answer by asafsitner · Sep 16, 2011 at 12:33 PM

To make this one work you'll have to manually add the HoldPosition game object to the player's hierarchy and position it where you want the hands to be.

 using UnityEngine;
 using System.Collections;
 
 public class ThrowTest : MonoBehaviour
 {
     public Transform HoldPosition; //This is the point where the "hands" of the player would be
     public float ThrowForce = 10f; //How strong the throw is. This assumes the picked object has a rigidbody component attached
     public float AlphaAmount = 0.5f; //this will be the alpha amount. It's public so you can change it in the editor
 
     private Transform _pickedObject;
     private Color _originalColor;
 
     void OnCollisionEnter (Collision collision)
     {
         if ( collision.transform.tag == "pickup" )
         {
             //caches the picked object
             _pickedObject = collision.transform;
 
             //caches the picked object's color for resetting later
             _originalColor = _pickedObject.renderer.material.color;
 
             //this will snap the picked object to the "hands" of the player
             _pickedObject.position = HoldPosition.position;
 
             //this will set the HoldPosition as the parent of the pickup so it will stay there
             _pickedObject.parent = HoldPosition;
 
             //this will change the alpha amount on the object's color to make it half transparent
             _pickedObject.renderer.material.color = new Color(_pickedObject.renderer.material.color.r,
                                             _pickedObject.renderer.material.color.g,
                                             _pickedObject.renderer.material.color.b,
                                             AlphaAmount);
         }
     }
     
     void Update()
     {
         if (Input.GetKeyDown("space"))
         {
             if (_pickedObject != null)
             {
                 //resets the pickup's parent to null so it won't keep following the player
                 _pickedObject.parent = null;
 
                 //resets the pickup's color so it won't stay half transparent forever
                 _pickedObject.renderer.material.color = _originalColor;
 
                 //applies force to the rigidbody to create a throw
                 _pickedObject.rigidbody.AddRelativeForce(transform.forward * ThrowForce, ForceMode.Impulse);
 
                 //resets the _pickedObject 
                 _pickedObject = null;
             }
         }
     }
 }
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 asafsitner · Sep 16, 2011 at 12:58 PM 0
Share

Forgot to add, but you'll want the pickup object to be rendered on a different layer, like you'd do with weapons. http://unity3d.com/support/documentation/$$anonymous$$anual/Cameras.html

avatar image
0

Answer by misterxxx · Sep 18, 2011 at 09:56 AM

thanks, i will try it later if i come home again :D

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Does anybody know how to create a consistent pick up and throwing system.,I need help creating a throwing system. (2D) 1 Answer

Throwing dice with the mouse 0 Answers

Can i have help writing a script to pick up and throw a ball (2D game) 1 Answer

[VR - Vive] Throwing shurikens with modified speed 0 Answers

throw objects based on mousemovement 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