# Catapult press spacebar to launch / throw

 0 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. more ▼ asked Mar 15 '12 at 08:11 AM COLLAnitySV 36 ● 21 ● 23 ● 25 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. Mar 15 '12 at 08:28 AM syclamoth i don't understand... it's keep flying Mar 15 '12 at 08:56 AM COLLAnitySV add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Mar 15 '12 at 08:43 AM fafase 10.4k ● 9 ● 15 ● 40 thanks its really works!!! Mar 15 '12 at 09:01 AM COLLAnitySV add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1781
x102
x57
x18
x8

asked: Mar 15 '12 at 08:11 AM

Seen: 967 times

Last Updated: Mar 15 '12 at 09:01 AM