I wanna get rid of this thing. my character enters a portal and I clicked ok to load the level and the moment my character lands on the scene, it start to move. I just want it to stand still on the spawn point and move only if I told it so or click somewhere in the map. do you know whats the problem… thanks here is the code:
var smooth:float; // Determines how quickly object moves towards position
var isWalking : boolean;
var lastP;
var move;
var pressed: boolean;
var standing : boolean;
var objectP ;
private var targetPosition:Vector3;
function Start()
{
animation.Stop();
animation.Play(“idle”); // this stops Unity from playing the character’s default animation.
standing = spawnPointScript.standing;
objectP = spawnPointScript.objectP;
}
function Update () {
pressed = false;
if(pressed== false)
{
if(Input.GetKeyDown(KeyCode.Mouse1))
{
smooth=5;
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}
move =transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime*smooth);
if(lastP != move)
{
if(!isWalking){
isWalking= true;
animation.Play(“walk”);
}
}
else
{
if(isWalking)
{
isWalking = false;
animation.Play("idle");
}
}
lastP =move;}
pressed = true;
}