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 sandhillceltic · Mar 13, 2013 at 12:20 AM · javascriptfirst person controllerthrow

Throwing an object on input

I am making a game where the player combines chemicals to make compounds which they use to complete challenges. I have written a code for the combining of the chemicals. I have two global variables, "water" and "HP"(Hydrogen peroxide), both made of Hydrogen and Oxygen. I have a problem with one of my scripts- the script that allows the player to "throw" the vial of chemicals. The input of a key is suppose to send the chemical vial (with rigidbody) flying in the direction the player is facing (first person). I need variables like "speed/power" and "Rigidbody" (for what the vial mesh is). I am decent with JavaScript, but know nothing about C#. I attempted this code, but I cannot figure out the vector () or any other force related commands. Can someone please try and explain either the Vector () command with examples, How I might approach this problem, or just explain to me how they would do the code?

This is URGENT!!!! I need it done by Sunday march 15th 2013.

also, I don't just want code. If you do give me code, can you explain what you did so I can learn from it?

I am really clueless to how to start this! I have read the Unity page on the Vector command.

-Thanks in advance

Comment
Add comment · Show 2
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 robertbu · Mar 13, 2013 at 02:56 AM 0
Share

Your throwing is just another projectile script. There are a bizillion projectile and shooter scripts on UnityAnswers. If this is first person, you likely looking for one that shoots from the center of the screen. Google this list for any combination of projectile, shoot, bullet, gun, center of screen. Read and play. Find a simple one and implement in a simple project. There are lots of beginner questions and answers. Pay attention to how to create prefabs, how to link a prefab with a script, how to attach a Rigidbody, transform.LookAt(), and how to add force to a rigid body.

avatar image amphoterik · Mar 13, 2013 at 03:21 AM 0
Share

What robertbu said is correct. You also may want to look into what vectors are as they play a large role in 3D development.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by amphoterik · Mar 13, 2013 at 03:27 AM

Assuming you have a "player" that will be the source of the vial, you could do something like what's posted below. This will create a vial at the player position (centered) and throw it along the z axis with a force of 1 (vial's mass will determine how effective this is). This was all typed in here so there may be some typos, but that is the gist.

 if(Input.GetButtonDown("Fire1")){
     var temp = Instantiate(nameOfVialPrefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), transform.rotation);
 
     temp.rigidbody.AddForce(0, 0, 1f);
 }
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
avatar image
0

Answer by makaka-org · Jun 19, 2018 at 12:03 PM

Hey, Guys!
Check my asset called Throw Control.

alt text alt text

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

12 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

copy position. 1 Answer

"Compilation Not Complete" keeps me from using my scripts. 0 Answers


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