- Home /
Bullets fall
hey i recently asked a question on this forum to know how to do a shooting script, found one!...but when i left click the bullet falls, no force so here is what i used please help me!:
var shot : Transform;
function Update()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var bullit = Instantiate(shot,gameObject.FindWithTag("Respawn").transform.position,Quaternion.identity);
} }
Answer by greatestprez · Nov 28, 2012 at 05:26 PM
All you are doing there is instantiating the bullet. for it to move you need to use RigidBody.addForce (if your bullet is a rigidbody)
Example:
var speed : int;
var shot : Transform;
function Update()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var bullit = Instantiate(shot,gameObject.FindWithTag("Respawn").transform.position,Quaternion.identity);
bullit.rigidboy.addForce(transform.forward * speed);
} }
I may be wrong here, but I think the forward direction is different to the Vector3.forward. I use transform.forward rather than Vector3.forward.
Answer by behzad.robot · Nov 28, 2012 at 05:40 PM
You Can Also Try
bullit.rigidbody.velocity.x = speed;
Or Maybe velocity.z it depends on your Shooter But addForceWorks well too it's just a matter of seeing which one works better for you! this things are also mentioned in Unity3d's FPS creating guide Part1!(I am recommending this caz this velocity was recommended by many tuts!)
Answer by darker9999 · Nov 28, 2012 at 09:31 PM
place a script on your prefab that contains:
function Start()
{
rigidbody.AddForce (vector3.forward * speed);
}
if you wish to prevent the bullets dropping off as they travel uncheck gravity on your prefab.
Your answer
Follow this Question
Related Questions
My character fall down on the ground ? 1 Answer
Player cant fall down 0 Answers
colliding bullets 2 Answers
Best method for creating bullets 2 Answers
Multiplayer FPS Bullets: should they be rigid bodies or raycast? 1 Answer