- Home /
Bullet spawning to low..
Hi I'm busy building an FPS part in my game but I'm unable to get the height of where the bullet is spawned right.. it keeps looking like I'm bowling or something...
I'm using the following code but I'm unable to find out why the bullets aren't spawning at the right place..
function Start () {
count = 0.5;
speed = 40;
}
function Update () {
count = count + Time.deltaTime;
//print(count);
if(count >= 0.5){
if (Input.GetButton("Fire1")) {
var clone : Rigidbody;
clone = Instantiate(projectile, (transform.position + Vector3(0.3, 0, 0)), transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.right * speed);
}
count = 0;
}
I'm assu$$anonymous$$g the code above is attached to an empty game object. I'm guessing this is a 2D game with 'Y' being 'up'. I suggest you make a small visible game object (like a sphere set to a size of (0.1, 0.1, 0.1), make it a child of the empty game object with a position of (0,0,0) (i.e. at the same position). The code above should instantiate 0.3 to the right of the visible object. If that is not the case, take a look at your prefab and make sure any parent/child relationships have appropriate offsets.
1.maybe there is only one rigidbody in one gameobject,so you should create a gameobject and attach the clone rigidbody on it
2.maybe your rigidbody‘s mass is zero,so it can't move with velocity
3.you can see nothing without a meshrender and a mesh,so you need a gameobject as 1
I figured it out, since the person who created the level used an imported game object from maya the player was 1 higher on the X axes than normal therefore it looked like the bullets were spawning and moving at the characters feet. hence me changing the vector3 of the instantiate to 1,0,0 solved the issue, thanks for the quick replies though
Your answer
Follow this Question
Related Questions
2D Shoot at Mouse Position; how to rotate towards the mouse? 1 Answer
Bullet Damage on different Limbs 1 Answer
Bullets spawn behind plane? 1 Answer
Shooting in direction of mouse cursor 2d 5 Answers