- Home /
Question by
Quanny · May 11, 2014 at 02:55 AM ·
gameobjectlookat
Is there currently a problem with .LookAt when using it in a script thats attached to a GameObject vs the Main Camera?
The reason why i ask is because i have 2 pieces of code, both look exactly the same, the one attached to the camera, it works great, however the one that is attached to a simple GameObject, is not physically working, the only rotation thats happening is when Blaster6 gets instantiated, it uses BlasterSpawnOP's rotation (which is a child of the GameObject that this script is attached to).
var Blaster6 = Instantiate(BlasterPrefab,
transform.Find("BlasterSpawnOP").transform.position,
GameObject.Find("PlayerShip").transform.rotation);
Blaster6.name = "b_" + remoteName + "1";
Blaster6.LookAt(GameObject.Find(remoteTarget).transform);
Blaster6.rigidbody.AddForce(transform.forward * 2000);
blast1 = false;
blast2 = true;
timeBlaster = Time.fixedTime;
Comment
What is the type of 'BlasterPrefab'? Can you post the rest of the script?
Best Answer
Answer by Quanny · May 12, 2014 at 12:09 AM
I ended up finding out the issue, it was supposed to be
Blaster6.rigidbody.AddForce(Blaster6.transform.forward * 2000);
NOT
Blaster6.rigidbody.AddForce(transform.forward * 2000);