- Home /
Bullet not coming out of gun properly after rotation
Hey Guys,
So right now I have a cylinder that is attached to a sphere. I have them both children of an empty game object called join. As of right now, whenever I want to shoot a bullet, it comes out of the gun at the right spot, but as I rotate the joint (to rotate both the sphere and cylinder as a turret) the bullet still comes out of the original spot. Although it does record the right direction to go, I would like it to always come out at the end of the cylinder gameobject. Here is my code sofar:
using UnityEngine; using System.Collections;
public class ProjectileController : MonoBehaviour {
public Rigidbody cannonball;
float power;
Vector3 force;
void Start () {
power = 100.0f;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Space)){
force = gameObject.transform.forward * power;
Rigidbody instance = Instantiate(cannonball,transform.position+new Vector3(0,0,1)*2,transform.rotation) as Rigidbody;
instance.AddForce( force );
}
}
}
I would like to make the part where I instantiate the cannonball have a dynamic spawn. Instead of the Vector3(0,0,1)*2, which only makes the cannonball come out correctly from its original position. Hopefully that makes sense, and thanks!
Your answer
Follow this Question
Related Questions
Angle to Rotation 2 Answers
0-360 Y degree from Vector3.Angle 1 Answer
Issue finding an angle with trigonometry 1 Answer