1
\$\begingroup\$

I just started a new proyect with a personalize first person controller, like arrow move style, it worked, but when I tryed to collide it with walls it did not happen, I tryed adding a capsule, then adding the camera, rigidbody, character controller and my script to that capsule , then if you can see there are two walls one with box collider trigger the other one unchecked, it walks around but it does not collide at all, i'll add my controller script + scereenshot, thanks for you time

#pragma strict public var speed = 100.5; function Update () { //rotate var horizontalDir = parseFloat(Input.GetAxis("Horizontal") * speed * Time.deltaTime); transform.Rotate(0, horizontalDir, 0); //move backward and foreward var verticalDir = parseFloat(Input.GetAxis("Vertical") * (speed / 10) * Time.deltaTime); transform.Translate(0,0, verticalDir); } 

screenshot

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

we update the script as follows

#pragma strict var walkSpeed = 150; var rotateSpeed = 100; var jumpSpeed : float = 8.0; var gravity : float = 20.0; private var moveDirection : Vector3 = Vector3.zero; function Update () { var controller : CharacterController = GetComponent.<CharacterController>(); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(0, 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= walkSpeed * Time.deltaTime; //also with jump ;) if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller controller.Move(moveDirection * Time.deltaTime); // rotate controller var horizontalDir = parseFloat(Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime); transform.Rotate(0, horizontalDir, 0); } 
\$\endgroup\$
1
\$\begingroup\$

Translating the Transform component directly doesn't not apply collision detection. You'll want to use Move() on the CharacterController.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.