I made a script that shoots but the bullet’s rotation is wrong when instantiated?I’m not sure how to rotate it, here’s my script:
using UnityEngine;
using System.Collections;
public class Theshoot : MonoBehaviour
{
public Rigidbody bulletPrefab;
public Transform barrelEnd;
void Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Rigidbody rocketInstance;
rocketInstance = Instantiate(bulletPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
rocketInstance.AddForce(barrelEnd.forward * 5000);
}
}
}
Make a new Empty Game Object and set it to position (0,0,0) with no rotation. Then rotate the Game Object you are using as a bullet to the way you want it to come out when you “fire” it. Then drop it into the Empty Game Object, and save that as a prefab (named whatever you want). Use that as your bulletPrefab. Then it should instantiate the Empty Object with no-rotation, but your bullet will be whatever direction you rotated it. If you need to change the bullets rotation, simply rotate the bullet Game Object inside of the Empty Game Object. The Empty Game Object’s rotation should always be (0,0,0).
Try doing
rocketInstance = Instantiate(bulletPrefab, barrelEnd.position, bulletPrefab.transform.rotation) as Rigidbody;
So you’re calling the bullets rotation, not the barrels.