- Home /
Question by
imaethan · Jul 11, 2012 at 06:32 PM ·
javascriptcharacter controllerstrafe
Character strafing problem (javascript)
I'm having trouble getting my character to strafe. I've currently got the following script working so I can run forward/backwards and also rotate around using the mouse. It's for a top-down game.
> > public static var speed = 10.0; var rotatationSpeed = 0.0; private var
> curSpeed = 0.0;
>
> function Start () {
>
> speed = 10;
>
> }
>
> function Update () { // Rotate around
> y-axis var newRotation =
> Input.GetAxis("Mouse X") *
> 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);
>
> if (cGUI.health <1) speed = 0;
>
> if (cGUI.health <1) rotatationSpeed =
> 0;
>
> var up=
> transform.TransformDirection(Vector3.up);
> controller.SimpleMove(forward *
> newSpeed); // Update the speed in the
> Animation script
> SendMessage("SetCurrentSpeed",
> newSpeed,
> SendMessageOptions.DontRequireReceiver);
> SendMessage("SetCurrentLean",
> Input.GetAxis("Horizontal"),
> SendMessageOptions.DontRequireReceiver);
>
> } @script RequireComponent
> (CharacterController)
Any help would be fantastic :)
Comment