Hello Everybody,
i was working for some Time on my Player and i wrote a Script. It is working well- but i can glitch throught walls and objects. I searched in Forums that i could use the Character Controller. I searched for the Character Controller Scripting but i did not really understand how i can use this in my script.
Can somebody show me how i implement a CC in my script- and its working like before? Transform.Translate was not a good idea! And the Character should walk and run at the same speed; if the framerate is 10 or 200, so if should be in Update() but * Time.deltaTime- or is this normal at the CC??
Please Help,
Thanks in Advance,
Heres my Code:
public float walkspeed;
public float runspeed;
[HideInInspector]
public Rigidbody rigid;
public float jumpspeed;
public GameObject cam;
[HideInInspector]
public bool isrunning;
[HideInInspector]
public bool walkshake;
public Rigidbody rigidb;
void Update()
{
if (Input.GetKey("left shift") && Input.GetAxis("Vertical") > 0)
{
float trans = Input.GetAxis("Vertical") * runspeed;
float strafe = Input.GetAxis("Horizontal") * runspeed;
trans *= Time.deltaTime;
strafe *= Time.deltaTime;
transform.Translate(strafe, 0, trans);
isrunning = true; //this bools are for the camera- play the run or walk shake anim- first person
walkshake = false;
}
else if (Input.GetKeyDown("space"))
{
rigidb.AddForce(0, jumpspeed, 0);
}
else
{
float trans = Input.GetAxis("Vertical") * walkspeed;
float strafe = Input.GetAxis("Horizontal") * walkspeed;
trans *= Time.deltaTime;
strafe *= Time.deltaTime;
transform.Translate(strafe, 0, trans);
if (trans > 0) {
walkshake = true;
}
else
{
walkshake = false;
}
isrunning = false;
}
}