How to instantiate a prefab infront of First Person Controller
Hello there im trying to Instantiate my Game object right in front of the Player and all is good but the Object is just a little off the terrain.
Here is what I got So far
var DupObject : GameObject;
if (Input.GetKeyDown(KeyCode.F)){
Instantiate(DupObject, transform.position + transform.forward*distance, transform.rotation);
}
Cast a ray downward, starting at the xy position of the placement spot but high up in the air. Use the hit.point (the point where the ray hits the ground) for the "real" placement spot.
Answer by undead504 · Jun 18, 2016 at 01:21 PM
First off let say Thanks @Cherno you Made me Look harder at my code and really think. OK so the DupObject was has High as the Hit and I added some code on the update to make it always =0 on the y AXIS. here is my Code if any one wants it.`#pragma strict var DupObject : GameObject; var distance : float=5; var Spot : GameObject; var OBJ : Transform; var Layer : int=1; var YAxis :float=0; function Start () {
}
function Update () { Spot.transform.position.y=YAxis; var foundHit :boolean=false;
var hit : RaycastHit; if (Input.GetKeyDown(KeyCode.E)){ Instantiate(DupObject, Spot.transform.position, transform.rotation); }
if (Input.GetButton("Fire1")){ foundHit= Physics.Raycast(transform.position,transform.forward,hit,Mathf.Infinity,1<