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 COLLAnitySV · Mar 15, 2012 at 08:11 AM · rigidbodyjointshingejointcatapultslingshot

Catapult press spacebar to launch / throw

hi everyone. i want to ask how to make the catapult throwing an object by pressing space (Not instantiate) ? It's similar with Angry bird game (pull the slingshot and release it, then the object will fly how far according to how far you pull the slingshot). You understand what i mean right ? sorry for my bad english.

any answers appreciated.

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 syclamoth · Mar 15, 2012 at 08:28 AM 1
Share

Well, the simplest way is to not use hinges or a slingshot at all, and to just use Rigidbody.AddForce in the correct direction. Certainly until your core game mechanics are down, that's what you should be doing.

avatar image COLLAnitySV · Mar 15, 2012 at 08:56 AM 0
Share

i don't understand... it's keep flying

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by fafase · Mar 15, 2012 at 08:43 AM

As I wanted to try for myself as well I came up with a simple form of it. The object in this case is only going up and falling down at a rate that is not the gravity. You still need to perfect it but at least you got a lead. What would you learn if I just give you the answer?

 var Start:float;    
 var End:float;
 var force:float = 0.0f;
 
 function Update(){
       // when space is pressed down the counter starts
       if (Input.GetKeyDown (KeyCode.Space)){
             Start = Time.time;
     }
     // When space is released the counter stops note that GetKeyDown/GetKeyUp does not do anything while keeping pressed
     if (Input.GetKeyUp (KeyCode.Space)){
             End = Time.time;
             force = (End-Start)*20;  // here you compare the 2 values I had to multiply by 20 to get it up (that's what she says) but you might have to alter this eqution to get what you want        
     }
     // the result is applied to the object rigidbody, only up in this case here again yo need to work it out
     rigidbody.AddForce(Vector3.up*force);
     force = force*0.9;  // force is decreased in time to get the object falling down
     Debug.Log("Start: "+Start+" End: "+End+" Force: "+force);//Just for debug...
 }

Hope that helps.

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 COLLAnitySV · Mar 15, 2012 at 09:01 AM 0
Share

thanks its really works!!!

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

Hinge Joint On Little Noodle Carton (with pic) 1 Answer

Hinges required for see-saw or catapult effect. 1 Answer

How to make an arm with multiple, controllable joints? 2 Answers

How to bend slingshot on stretch? Like angry birds 2 game 0 Answers

Hinge Joint Breaks When LocalScale is Changed 3 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