- Home /
Question by
Fr0stbite · Feb 08, 2014 at 02:36 PM ·
instantiateraycastdistanceraycasthit
Position before the camera?
In my script i use RaycastHit:
var hit : RaycastHit;
if(Physics.Raycast(transform.position,transform.forward,hit,100)){
Instantiate(prefab,hit.point,Quaternion.identity);
}
if it doesn't hit other object i want to instantiate the prefab at the end of raycast. Is it possible?
Comment
Best Answer
Answer by Fr0stbite · Feb 08, 2014 at 08:17 PM
Instantiate(prefab,transform.position + transform.forward*100,transform.rotation);
Answer by getyour411 · Feb 08, 2014 at 03:05 PM
var defPos = Vector3(transform.forward.x, transform.forward.y, transform.forward.z+100);
Instantiate(prefab, defPos, rot);
I don't do JS so syntax might be a bit off
it instantiates the prefab at 0,0,100 (i use this script from a gameobject of the fps camera)
Your answer
Follow this Question
Related Questions
Drawing a line in front of player weapon 0 Answers
Instantiate gameobject a certain distance away from transform 2 Answers
How can I instantiate an explosion using Raycasting? 0 Answers
RaycastHit.distance 1 Answer
Raycasts don't go the right direction unless i'm really far away (javascript) 1 Answer