- Home /
C# Bullets do not fly, just fall...
I have been going nuts over this, I checked all of my things to make sure collision is not to blame, and I made sure the bullet had a ridged body, and I'v tried 5 different codes, but all they do is fall down. I even changed the rotation of the bullet to make sure "Forward" wasn't down, but they still all fall. T_T
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public float bspeed = 500;
public Transform shootfrom;
public Rigidbody bullitt;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.LeftShift))
{
Rigidbody shooting;
shooting = Instantiate(bullitt,shootfrom.position,transform.rotation)as Rigidbody;
shooting.velocity = transform.forward * bspeed;
}
}
}
Answer by Hez · Jan 31, 2013 at 01:43 PM
I found an answer myself, I just made a new scrip and applied it to the bullet.
using UnityEngine;
using System.Collections;
public class onwords : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(Vector3.forward * 1 * Time.deltaTime);
}
}
using transform.Translate() means that the object will not calculate collisions. Apply force using AddForce() and the physics engine will handle collisions.
Thanks, that saved me from looking on the internet, for ever, later :D
Answer by Berenger · Jan 31, 2013 at 09:58 AM
bullit is declared as GameObject. Either declare it as rigidbody, or instantiate a GameObject and use shooting.rigidbody.velocity.
That got rid of the error message :D but the bullets still fall to the ground. I am going to update the code in the thread, people may think you are nuts :P
Answer by Qvintusdk · Jan 31, 2013 at 11:20 AM
your making sure shootfrom.position isn't inside another object right? It could also be because your mass on the bullet is a bit too high?