- Home /
Instantiate at raycast position
Hi, if anyone could tell me how i could instantiate a object at the position of where a raycast hits. any help would be gladly appreciated.
There is too little information here to point you at a good answer. What is casting the ray? Do you have your source you want to merge this code into?
Answer by Cyberpie_n_milk · Mar 16, 2013 at 03:32 PM
Add a RaycastHit to you raycast. You will then be able to get the position where the ray hit something or the transform that it hit etc. About RaycastHit.
Example:
var hit:RaycastHit;
if(Physics.Raycast(origin, direction, hit)){
instantiatedObject.transform.position = hit.point;
}
Your answer
Follow this Question
Related Questions
How to prevent GameObject from spawning on top of each other? 1 Answer
Instantiated an Prefab on a Spherical Object at mouse cursor position 3 Answers
Use OnMouseOver or Raycasting while also displaying a camera texture. 0 Answers
Instantiate gameobject at mouseposition 2d 2 Answers
help with scripting combo points 1 Answer