08-04-2016, 08:14 PM
(Questo messaggio è stato modificato l'ultima volta il: 08-04-2016, 08:16 PM da Blackg96.)
Codice:
variabili :
private float charHeight;
private float h;
private Vector3 pos;
public CharacterController charCont;
public float speedToCrouch = 18;
funzione :
if(Input.GetKey(KeyCode.C)) h = 1;
else h = 2;
float lastHeight = charCont.height;
charCont.height = Mathf.Lerp(charCont.height, h, Time.deltaTime * speed);
pos.x = charCont.transform.position.x;
pos.z = charCont.transform.position.z;
pos.y = charCont.transform.position.y + (charCont.height - lastHeight) / 2;
charCont.transform.position = pos;