Hi, I have a setup where a camera can move around a scene. The user can hit a button that draws a ray to hit the ground plane in front of the camera, then the idea is that it translates the ground plane from where the ray hits to be directly underneath the camera. So this would be moving the ground, not the camera/player. Sort of like a tractor beam on the world.
I think because of parenting issues maybe the local vs. world space is messing things up. Also I may need a better reference to the direction toward the camera from the ray hit to get the right move vector. Can anyone spot the issues with this? The ground plane is not moving from the ray hit spot to underneath the camera. It seems to move according to it’s own axis.
IEnumerator MoveFrom()
{
Plane plane = new Plane(Vector3.up, Vector3.zero);
Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
float distanceHit;
if (plane.Raycast(ray, out distanceHit))
{
Vector3 hit = ray.GetPoint (distanceHit);
}
Vector3 vector = hit;
Vector3 lastVector = ground.transform.localPosition;
Vector3 diffVector = vector - lastVector;
Vector3 vectorNew = new Vector3(diffVector.x, lastVector.y, diffVector.z);
float t = 0;
while (t<1.0f)
{
t += Time.deltaTime/time;
ground.localPosition = Vector3.MoveTowards(lastVector, vectorNew, t);
yield return null;
}
}