x


Having trouble moving character backwards...

I already have my character moving forward and rotating, but having trouble moving backwards... Here is my code for moving forward:

  function moveForward(){
    //Move forward
    forward = trans.forward * Time.deltaTime * moveSpeed;

    //move character on key pressed
    if(Mathf.Abs(Input.GetAxis("ForwardBack")) > 0){
        transform.Translate(forward);
    }   
}

Any suggestions? I've followed burgZerg Arcade's tutorial on Youtube (video 93.) on this, but it doesn't work for me...

more ▼

asked Nov 05 '11 at 05:00 PM

altLinx gravatar image

altLinx
1 3 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
`enter code here`in Update

var controller : CharacterController = GetComponent(CharacterController);

var forward = transform.TransformDirection(Vector3.forward);

var curSpeed = speed * Input.GetAxis ("Vertical");

transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

 //Move the controller
controller.Move(moveDirection * Time.deltaTime);

// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;



}

@script RequireComponent(CharacterController)
more ▼

answered Nov 05 '11 at 08:49 PM

superventure gravatar image

superventure
670 44 54 63

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1081
x213
x109
x26
x6

asked: Nov 05 '11 at 05:00 PM

Seen: 774 times

Last Updated: Nov 05 '11 at 08:50 PM