c# - Crouch Script/ Scaling transform from one side only -


im trying make crouching script there's wrong code, i've been stuck in here many hours , still don't know what's wrong.

im trying decrease height of player transform crouch, , increase stand up.

here's code:

public float crouchspeed; public float crouchwalkspeed; public bool iscrouching = false; public bool iscrouched = false;  void update () {      crouch();     iscrouchingvoid(); }  public void crouch()     {         if(input.getkeydown(keycode.leftcontrol) && isongroud)         {             iscrouched = !iscrouched;             iscrouching = true;         }     }      public void iscrouchingvoid()     {         if(!iscrouched)         {             if (iscrouching)             {                     vector3 temp = transform.localscale;                     temp.y -= crouchspeed / 60;                     temp.x = 1f;                     temp.z = 1f;                     transform.localscale = temp;                  if (temp.y <= 0.5f)                 {                     temp.y = 0.5f;                     iscrouching = false;                 }             }         }          else if(iscrouched)         {             if (iscrouching)             {                     vector3 temp = transform.localscale;                     temp.y += crouchspeed / 60;                     temp.x = 1f;                     temp.z = 1f;                     transform.localscale = temp;                  if (temp.y >= 1f)                 {                     temp.y = 1f;                     iscrouching = false;                 }             }         }     } 

thank you.

edit:

im using charactercontroller component using physics.capsulecast feature isn't option.

have tried using charactercontroller's height property?

you can reduce height in iscrouchingvoid() method instead of playing scale behaviour of crouching.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -