Hi everyone, I’m creating a maze game for my final project at uni, but I am having quite a bit or trouble, i basically want my main charcter to walk into a wall and no go through it! But i dont know anything about rigid bodies or anything so all i have is a main charcter walking on a plane and a wall. here is the script to make the character walk:
var speed = 3.0; var rotatationSpeed = 200.0; private var curSpeed = 0.0; function Update () { // Rotate around y-axis var newRotation = Input.GetAxis("Horizontal") * rotatationSpeed; transform.Rotate(0, newRotation * Time.deltaTime, 0); // Calculate speed var newSpeed = Input.GetAxis("Vertical") * speed; if (Input.GetKey("left shift")) newSpeed *= 1.5; // Move the controller var controller : CharacterController = GetComponent (CharacterController); var forward = transform.TransformDirection(Vector3.forward); controller.SimpleMove(forward * newSpeed); // Update the speed in the Animation script SendMessage("SetCurrentSpeed", newSpeed, SendMessageOptions.DontRequireReceiver); SendMessage("SetCurrentLean", Input.GetAxis("Horizontal"), SendMessageOptions.DontRequireReceiver); }
Please help me. Thank for your time!!