crouch script

hi, i am making a game and have no idea what im doing wrong here, i am trying to make a script to crouch the character (fps), im using the physicswalker and have a spere with a colider on the grond that is “the feet” that is a child of the player so what i want to do is to have a button that makes the distance between the sphere and the player have a lower value, when i push the button, the position doesnt decrease, here is my script
(the value is right if i dont have the if(Input.GetKey(“r”)) in the script, but then it stays like that all time obviously)

function Start ()
{
if(Input.GetKey(“r”))
{
transform.localPosition = Vector3(0, -0.5, 0);
}
}

what am i doing wrong?

Start() is only called once (the first time the object is activated, according to the documentation).

You should do this in Update() which is called every frame. Something like:

function Update()
{
    if(Input.GetKey("r"))
    {
        transform.localPosition = Vector3(0, -0.5, 0);
    }
    else
    {
        transform.localPosition = Vector3(0, 0, 0);
    }
}

I made this that will solve your problem, it scales your fps controller so that it looks like you’re crouching…no problems with me so far…:slight_smile:

  1. var tongle = 0; var localScale :
    Vector3; //var JumpSpeed = 100.0f;

    function Start () {
    Screen.showCursor = false; }

    function Update () {

    if (tongle == 0){ if
    (Input.GetKeyDown
    (KeyCode.LeftControl)) {
    transform.localScale +=
    Vector3(0.0,-1,0); tongle = 1;
    } return; }

    if (tongle == 1){ if
    (Input.GetKeyDown
    (KeyCode.LeftControl)) {
    transform.position.y += 0.5;
    transform.localScale +=
    Vector3(0.0,1,0); tongle = 0;
    } return; }
    }

I made this that will solve your problem, it scales your fps controller so that it looks like you’re crouching…no problems with me so far…:slight_smile:

  1. var tongle = 0; var localScale :
    Vector3; //var JumpSpeed = 100.0f;

    function Start () {
    Screen.showCursor = false; }

    function Update () {

    if (tongle == 0){ if
    (Input.GetKeyDown
    (KeyCode.LeftControl)) {
    transform.localScale +=
    Vector3(0.0,-1,0); tongle = 1;
    } return; }

    if (tongle == 1){ if
    (Input.GetKeyDown
    (KeyCode.LeftControl)) {
    transform.position.y += 0.5;
    transform.localScale +=
    Vector3(0.0,1,0); tongle = 0;
    } return; }
    }

I made this that will solve your problem, it scales your fps controller so that it looks like you’re crouching…no problems with me so far…:slight_smile:

var tongle = 0;
var localScale :
Vector3; //var JumpSpeed = 100.0f;

function Start () {
Screen.showCursor = false; }





function Update () {

if (tongle == 0){ if
(Input.GetKeyDown
(KeyCode.LeftControl)) {    
transform.localScale +=
Vector3(0.0,-1,0);    tongle = 1;   
}    return; }


if (tongle == 1){ if
(Input.GetKeyDown
(KeyCode.LeftControl)) {   
transform.position.y += 0.5;   
transform.localScale +=
Vector3(0.0,1,0);    tongle = 0;   
}    return; }

}

P.S. sorry if i spammed that i wasn’t sure if i did post it right