Im having an issue when Instantiate Prefab with specific rotation
So, here is the thing, Im traying to instantiate a bullet prefab on my Enemy Ship, i put a child GameObject into my Enemy Ship called SpawnPoint and by reference on the inspector i use it transform.position and transform.rotation to instantiate my Bullet.
The Enemy ship and the Enemy Bolt have a "Mover" script with 2 line of code:
public class Mover : MonoBehaviour {
public float speed;
Rigidbody myRigidbody;
void Start () {
this.myRigidbody = GetComponent<Rigidbody>();
this.myRigidbody.velocity = Vector3.forward * this.speed;
}
}
The Enemy Ship have a WaeponController()
public class WeaponController : MonoBehaviour {
public GameObject shot;
public Transform shotSpawn;
public float delay;
public float fireRate;
AudioSource audioSource;
void Start () {
this.audioSource = this.GetComponent<AudioSource>();
InvokeRepeating("Fire", this.delay, this.fireRate);
}
void Fire () {
Instantiate(this.shot, this.shotSpawn.position, this.shotSpawn.rotation);
this.audioSource.Play();
}
}
Like you can see, the Instantiate() function use the shotSpawn reference for position and rotation, the problem is that the Bolt enemy prefab instantiated never take that rotation, always go at the opposite side of the screen..
Is there a logical explanation?
I am going to take a guess, rotation needs to be a Quaternion.
http://docs.unity3d.com/ScriptReference/Transform-rotation.html
this.shotSpawn.rotation is not a Quaternion? $$anonymous$$aybe i have to reference it in a Quaternion first? Like Quaternion quat = this.shotSpawn.rotation
Edit: nope, it does not work...
Answer by kevinrocks_786 · Nov 24, 2015 at 12:13 AM
Try removing the "this." from this.shotSpawn.position, this.shotSpawn.rotation
Answer by martibergoglio · Nov 24, 2015 at 11:20 AM
I tryed but not working. I think something wierd is happening with my shotSpawn rotation, while turning the object, the arrows that represent it never change position...
Your answer
Follow this Question
Related Questions
I need help destroying a clone on function. 1 Answer
All instantiated objects having same location, 0 Answers
Prefabs not instantiating after build 0 Answers
GameObjects rotation 0 Answers
How to spawn a prefab at a duplicate objects location 1 Answer