- Home /
Rotate "ghost object" then instantiate object with that rotation
I have a script which has a "ghost object" of a object that will be instantiated, and I want to be able to rotate the ghost object and then instantiate with the same rotation as the ghostobject.
This is void Update()
if(Input.mousePosition != startingMousePosition)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.DrawLine( Camera.main.transform.position, hit.point, Color.red );
//rayHitPoint = hit.point;
Object1.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
if (Input.GetButton("RotateInst")){
Debug.Log ("RotateInst cliked");
Object1.transform.Rotate(Time.deltaTime, 1, 0);
}
}
And here is void RaycastToTerrain() (the important stuff)
RaycastHit hit;
Ray rayPos = Camera.main.ScreenPointToRay( Input.mousePosition );
if ( Physics.Raycast( rayPos, out hit, Mathf.Infinity ) )
{
Debug.DrawLine( Camera.main.transform.position, hit.point, Color.red );
rayHitPoint = hit.point;
}
if(Input.GetKeyDown(KeyCode.Mouse0)){
Debug.Log ("Instantiating Windmill.");
Instantiate(Object1, hit.point, Quaternion.identity);
}
As you can see in the Update function you press the button "RotateInst" (which is arrowkeys) to rotate the object. How do I give that rotation to the instantiate method?
Thanks!
If this "Ghost Object" is a existing game object in scene, just use its rotation..
Instantiate(Object1, hit.point, ghostobject.transform.rotation);
If isn't, explain what is it..
@Gjallanhorn O$$anonymous$$G you're a genius! Please make it an answer so I can give you karma :D
Answer by Gjallanhorn · Oct 12, 2013 at 01:07 PM
If this "Ghost Object" is a existing game object in scene, just use its rotation..
Instantiate(Object1, hit.point, ghostobject.transform.rotation);
Your answer
Follow this Question
Related Questions
Simple rotations question 2 Answers
How get the rotation of an GameObject? 3 Answers
Rotate around a locally tilted axis?, 1 Answer
Anyone know why this isn't working? 1 Answer
Rotation is jumpy 2 Answers