I want to be able to instantiate a bullet object on an enemy tank with a specific angle trajectory. This is what I have so far…
function ShootCannon(){
//this is the position of fire at the muzzle of the tank
var firePos = Vector3(transform.position.x + 3.05,transform.position.y + 1.05,transform.position.z);
//this is the bullet creation
var instance = Instantiate(Bullet, firePos, transform.rotation);
instance.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);
//note: I want the rotation of the actually fireing to have an
//angle of +20 degrees from which the bullet comes out of.
I see the way your doing it and I think that that is a unneeded approach to what you are trying to do. When ever I work with bullet spawns I would either use ray cast and there’s a billion tutorial on that or the best option for what your doing is to make a bullet spawn object.
Create a empty game object
Name it as Desired
Position it linked to the tank’s barrel as a child and rotate it to the desired degree
Then fix the code…
var firePos : Transform;
function ShootCannon(){
//this is the bullet creation
var instance = Instantiate(Bullet, firePos.position, firePos.rotation);
instance.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);
//note: I want the rotation of the actually fireing to have an
//angle of +20 degrees from which the bullet comes out of.
In my opinion this is a very simple and effective way to solve your issue.
Warning Did not Test Code so there may be some simple errors but I dont think so…