I have searched through numerous threads about this and still can’t grasp how this is supposed to work:
I have 2 Vector3 points (spawnPosA and spawnPosB), and from them I get elementObjectLocation using Lerp which works correctly (basically the middle point). On that point I instantiate my prefab which is basically a cylinder. I want the top of my cylinder to face point spawnPosB (or spawnPosA, the result should be the same). I have attempted to use “Quaternion.FromToRotation”, “Quaternion.LookRotation” and can’t figure out how it works. I have also tried to manually calculate angles and use eulerAngles but that turns out to be even more of a trouble.
My code, without any rotation attempts:
public void SpawnPipe(Vector3 spawnPosA, Vector3 spawnPosB)
- {*
-
int i = SpawnPoint ();*
_ elementObjectLocation = Vector3.Lerp (spawnPosA, spawnPosB, 0.5f);_
elementObject = Instantiate (Resources.Load (“ModelPrefabs/Pipe1”), elementObjectLocation , Quaternion.identity)as GameObject;
* //Insert rotation code here*
_ elementObject .transform.localScale = new Vector3(1,Vector3.Distance (spawnPosA, spawnPosB),1); //this one is to stretch the object, does not affect the result
* }
Here is a picture I drew if I did not explain that pretty well:
![alt text][1]
[1]: http://i59.tinypic.com/2cyjs6t.jpg*_