- Home /
Unity Raycast Script, Help!
Hi. My problem is that: I create this script:
var blue : GameObject;
static var mozna : boolean = false;
static var moznaa : boolean = false;
function Update () {
var hit : RaycastHit;
if(Physics.Raycast (transform.position, transform.forward, hit, 1000)){
mozna=true;
if(moznaa==true){
var Newblue : GameObject;
Newblue = Instantiate(blue, hit.collider.gameObject.transform.position, hit.collider.gameObject.transform.rotation);
}
}
}
And when I shoot in a wall, blue create at the central point this wall. I want to create at any point no on a central point. Please Help!
Comment
Answer by robertbu · Aug 09, 2013 at 02:51 PM
To get the position correct use hit.point. You may want to bring the object out just a bit to avoid 'z' fighting. I'll have to guess on the rotation since I don't know the natural orientation of blue. Typically this kind of code would use a horizontal plane:
Newblue = Instantiate(blue);
blue.transform.position = hit.point + hit.normal * 0.01;
blue.transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * blue.transform.rotation;
Your answer
Follow this Question
Related Questions
Particle Instantiation problem. 0 Answers
raycast from an empty gameobject? 1 Answer
EteeskiTutorials' bullets (raycast bullets with gravity) 1 Answer
How to get information from raycast? 2 Answers