Question by
PrinceHackerman27 · Feb 09, 2016 at 12:27 PM ·
c#quaternionrotatetransform.rotation
How can I add rotations to transform.rotation?
So, I'm trying to make an FPS game with Instantiate as a bullet method. I want the bullet to rotate either 90 or -90 degrees(I haven't determined which) across the gun's rotation. (i.e. if the gun is at 0, 90, 0, I want the bullet to spawn at 0, 0, 0, or 0, 180, 0, depending on which it is.) I've tried multiplying transform.rotate by Quaternion.Euler(0, -90, 0) , but no matter what the y is the bullet rotates to face the wrong way, but 90 degrees. Here's the code:
using UnityEngine;
using System.Collections;
public class FiringScript : MonoBehaviour {
Animator anim;
public GameObject Bullet;
public float BulletSpeed = 100.0f;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("mouse 0")) {
anim.SetBool ("Recoiling", true);
GameObject Bullet2 = Instantiate(Bullet, transform.position, transform.rotation * Quaternion.Euler(0, -90, 0)) as GameObject;
} else {
anim.SetBool ("Recoiling", false);
}
}
}
Any suggestions?
Comment