# How do I get the collision position of the gaze input

I'm trying to move a Third-Person character by looking at random objects in the scene using the googleVR Rectile, what I had in mind is lerping the character to the collision point position. Any Help how to do this ?

• Can you clarify whether you're trying to move the player's viewing position, or the position of a character the player is looking at from a third-person perspective? – DMGregory Jul 31 '17 at 21:32
• its a third-person character actually – Saifiction Jul 31 '17 at 23:27
• This kind of detail is important to include in your question. ;) – DMGregory Jul 31 '17 at 23:27

In first person mode, where the user is moving themselves by looking around, the reticle is always in the center of the screen. So you can just as easily move forward to achieve the same effect.

Either with a straight constant movement:

void Update() {
this.transform.Translate(transform.forward * Time.deltaTime);
}


or do a Raycast to ensure the player is looking at one of your specified objects:

void Update() {
if(Physics.Raycast(transform.position, transform.forward,
{
this.transform.Translate(transform.forward * Time.deltaTime);
}
}


Where all the objects that cause the player to move forward are in the layer 'MyObjectLayer".

In a third person scenario, or if you've moving something other than the player, you'll want to get the position of the hit, so you can move the target object toward that position.

For that, use this version of Raycast:

public GameObject targetObject;

void Update() {
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit,
{
Vector3 direction = MoveTowards(TargetObject.transform.position,
hit.point, Time.deltaTime);
targetObject.transform.Translate(direction);
}
}


Where targetObject is the object you want to move toward the hit point.

• Is there anyway that I can get the collision point ? – Saifiction Jul 31 '17 at 20:08
• Yes, of course, but there's little point as far as the movement goes. I've updated the answer. – MichaelHouse Jul 31 '17 at 20:20
• I think this assumes a first-person perspective — that the character you're moving is also your viewpoint. If it's a third-person perspective like Lucky's Tale, then moving the character pawn toward the gaze position is not the same as moving the viewpoint forward. – DMGregory Jul 31 '17 at 21:07
• @DMGregory Yes, I suppose I hadn't considered that scenario. That would be rather ambitious with Google Cardboard, but certainly possible. – MichaelHouse Jul 31 '17 at 21:21