- Home /
How to make a gun shoot?
Hi,
I have a gun, a bullet GameObject, and an empty spawnpoint GameObject. But I don't know how to make my gun shoot the GameObject. Help please!!
ps. if you are going to suggest a script to me, please make it javascript! :D
THANKS SO MUCH!!!
Here are some links I strongly suggest to all new users :
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/
this is the YouTube link for the above as one playlist : http://www.youtube.com/watch?v=-oXYHNSmTxg&list=PL27B696FB515608D2&feature=plcp
Character controller and terrain : http://cgcookie.com/unity/2011/12/05/introduction-to-character-controllers/
That is good to get started. Then start with a small tutorial, this is a simple 2D space shooter : http://www.unityjumpstart.com/ProofOfConcept_1/ : click on the videos part1.mp4 part2,3,4 =]
I just found another by our own Eric : http://wiki.unity3d.com/index.php?title=2DShooter : http://forum.unity3d.com/threads/7883-2D-shooter-tutorial
By then you should be getting the hang of things and starting to have ideas of your own. When you decide what kind of game you want to make, then look at each part you'll need. For example, if you want to make some terrain then walk around it with a character : http://cgcookie.com/unity/2011/12/05/introduction-to-character-controllers/
Here's another on the same 'site but I havn't checked the difficulty : http://cgcookie.com/unity/2012/02/24/game-planning-lunar-lander-01/
Basically then just search for tutorials, there are many out there, either written or on youtube.
the Unity Wiki tutorials : http://wiki.unity3d.com/index.php/Tutorials
A big list of tutorials : http://answers.unity3d.com/questions/12321/how-can-i-start-learning-unity-fast-list-of-tutori.html
Helpful page with information on using Built-In Arrays and Lists (you'll need this later!) : http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?
The unity wiki link above is very handy with lots of scripts and shaders too (just check out all the links down the left, and the tabs along the top : http://wiki.unity3d.com/index.php/Scripts )
http://answers.unity3d.com/questions/148211/list-of-frequently-asked-beginners-questions.html
http://forum.unity3d.com/threads/132628-How-to-help-the-Absolute-Beginner
If you know what kind of game you want to make, edit your question and write there what you are thinking of, then there may be a tutorial out there for that!
But just be aware, you will do lots of typing, deleting, typing, bashing head on desk, being really happy when it works and you understand how and why. I hope this helps, Happy Coding =]
Hey dude, I'll post this as a comment since it's a tip, not a full fledged answer.
You may be thinking what you need is a way to make the gun shoot out a bullet and destroy the GameObject when it makes contact.
This however is incorrect. What you actually want to do is use what is known as a RayCast. You can set a distance for the raycast as well as a point of origin and direction. It's basically a line cast out. What you can say is if that line is hitting the GameObject (You are ai$$anonymous$$g at the GameObject) and the user presses the fire button, then handle anything that needs to be done.
The bullet can be Instantiated(spawned), but that is merely a visual cue for the player, not in fact the actual deciding factor of whether it hit the object or not.
As far as I am aware this is how most, if not all first person shooters handle it
Answer by Warren Pope · Dec 06, 2012 at 07:01 AM
var BulletPrefab : GameObject;
function Update() { if(Input.GetButton("Fire1") {
bullet = Instantiate(BulletPrefab; gameObject.Find("Spawn").transform.position; Quaternion.identity)
bullet.rigidbody.AddForce(transform.forward * Speed);
}
}
Copy this script to your gun. create an empty gameobject, rename it to "Spawn" and place it in front of your gun. create your bullet and make it a prefab add a rigidbody to it drag this prefab to your script in the gun and place it in BulletPrefab set your speed When you click the left mouse button, the bullet should move forward in the speed you have set
none of this belongs to me.The credit goes to the tornado twins.i saw this video on youtube
Answer by sandeepsmartest · Dec 06, 2012 at 07:01 AM
function Update()
{
if(Input.GetButtonDown("Jump"))
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
}
}
this is the best way for instantiating bullets with certaine force.hope this helps.sorry if am wrong.thanku
Don't worry now, I already have a script! $$anonymous$$y problems are solved!
Your answer
Follow this Question
Related Questions
Setting bullet instansiate direction? help? 1 Answer
Bullets will not fire forwards 1 Answer
Shooting. Bullet floats and sprays 1 Answer
Troubles With A Shoot Script 1 Answer
Bullet Drop With Raycast 4 Answers