- Home /
Duplicate Question:
https://www.google.com/?gws_rd=ssl#safe=off&q=unity+bullet+prefab+faces+wrong+way
FPS Bullet spawn problem
Hi! My FPS is almost done, but i have a little problem that i wasn't able to solve. When i shoot with my gun, the bullet prefab spawn in the wrong direction, like in the image that i uploaded. No matter if i i change the direction of the prefab, when it spawns, it is in the wrong direction, making the bullet look like ridiculous! What i need to do so the bullet spawns in the right angle?
Here's my shooting script:
using UnityEngine; using System.Collections;
public class ShootDemo : MonoBehaviour { public Rigidbody projectile; public float speed = 0;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
}
}
}
Answer by Tyche10 · May 12, 2016 at 05:26 PM
I think you can find the answer in this unity tutorial: http://unity3d.com/learn/tutorials/modules/beginner/scripting/instantiate. Add an empty gameobject with the right position and rotation, drag it into a public Transform variable in your script and use its transform position and rotation in the instantiate function.
It's also possible to set the rotation after instantiating.
Yeah i know! SpawnPoint empty game object! I already have done this. SpawnPoint is the bullet spawner and there's only one side i can rotate it so it shoot the bullet correctly, but if i do this the bullet will spawn in an reverse way (it will go back) and i can't just rotate the map!