Hello, I have a 2d game that is laying down in the x & z. You click and drag a game object across the screen. This work, the only problem I have is, when I get the 'hit.point' the 'y' that gets returns is extremely 'high'. I try and set it manually after but it glitches and jumps back and forth from the 'y' in the hit.point to the 'y' that i set manually. Any help at all would be greatly appreciated. Thanks Fabrizio
function Update ()
{
if (Input.GetButton("Fire1"))
{
var ray: Ray = mCamera.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit))
{
if(!rockCreated)
{
var rock: GameObject;
var newPosition = Vector3(hit.point.x, hit.point.y, hit.point.z);
rock = Instantiate(rockPrefab, newPosition, City.transform.rotation);
Physics.IgnoreCollision(rock.collider, City.collider);
currRock = rock;
}
}
if(rockCreated)
{
Debug.Log("Y position of Hit" + hit.point.y);
currRock.transform.position.x = hit.point.x;
currRock.transform.position.z = hit.point.z;
//currRock.transform.position.y = hit.point.y;
}
}
}
It would help if we could see your ray variables (i.e. start, direction) and possibly have an idea of where your colliders are.
– Peter_GHi, sorry if i'm not sure exactly what you are referring to. Which 'start,direction' are you referring to? The Rock? Since it is instantiated, the start is where you click? Again, sorry if i don't understand exactly what you are asking. Thanks
– anon10727074