Hello,
If I press Space, I want the player translate to the pnj “statique” if the statique in a range between 1 and 3 from the player.
using UnityEngine;
using System.Collections;
public class deplacement : MonoBehaviour {
public Transform zag;
private bool moving = false;
private Vector3 startPosition;
private float Weight = 0;
private float liftSpeed = 3;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GameObject[] statiques;
statiques = GameObject.FindGameObjectsWithTag("Statique");
foreach (GameObject statique in statiques) {
float dist = Vector3.Distance(statique.transform.position, transform.position);
if (Input.GetKeyDown("space")){
startPosition = transform.position;
moving = true;
}
if ( (dist < 3) && (dist > 1) ){
if(transform.position == statique.transform.position){
moving = false;
}
if(moving ==true) {
Weight += Time.deltaTime * liftSpeed; //amount
transform.position = Vector3.Lerp(startPosition, statique.transform.position, Weight);
}
}
}
}
}
Problem is, the player move but stop when the distance beetween him and the closest statique = 1.