Im having a curious problem when using Linecast on an enemy (NPC) to detect the Player which is an instance of the "First Person Controls"-prefab (or FPC from now on) in the iPhone Standard Assets.
It will detect the FPC if it is within range and the FPC-object is moved manually within the scene-editor using the mouse. This also changes in real time the values of the FPC's Transform->Position in the Inspector.
But when using the actual controls of the iPhone (via the remote) the FPC is completely ignored by Linecast. Also, the values in the Inspector does not change when moving (Transform->Position).
Ive noticed one curious thing: if the FPC is selected in the Scene-editor and moved by the iPhone via the remote, the center of the FPC will not follow the actual object completely, but stick to a middle point from where the FPC was spawned and where it acually is at any given moment. It's as if the FPC actually got bigger (thus displacing its center) rather than moving.
Another weird thing (which might be a clue for the insighful) is that Raycast does not display the same problems when detecting the FPC.
Anybody have an explanation and preferably also a solution to this weird behaviour?
</p>
<p>var target : Transform;</p>
<p>var smooth : float = 1.0;</p>
<p>function Update ()</p>
<p>{</p>
```
if( Physics.Linecast( transform.position, target.position ))
{
// TODO: Check distance
// Doesnt work when moving player with iPod
if( Vector3.Distance( target.position, transform.position ) < 10.0 )
{
// Rotate towards player
var targetPoint = target.transform.position;
var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
// Move towards player
var targetPosition = Vector3(target.position.x, transform.position.y, target.position.z);
transform.position = Vector3.Lerp( transform.position, targetPosition, Time.deltaTime * smooth );
}
}
```
<p>}</p>